Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

HashStatic.h

00001 //   -*- C++ -*-
00002 /*****************************************************************************
00003  *
00004  *   |_|_|_  |_|_    |_    |_|_|_  |_                C O M M U N I C A T I O N
00005  * |_        |_  |_  |_  |_        |_                          N E T W O R K S
00006  * |_        |_  |_  |_  |_        |_                                C L A S S
00007  *   |_|_|_  |_    |_|_    |_|_|_  |_|_|_|_                      L I B R A R Y
00008  *
00009  * $Id: HashStatic.h,v 1.7 2002/02/01 08:45:56 spee Exp $
00010  *
00011  * CNClass: CNHashStatic --- hash tables with static number of entries
00012  *
00013  *****************************************************************************
00014  * Copyright (C) 1992-2002   Communication Networks
00015  *                           Aachen University of Technology
00016  *                           D-52056 Aachen
00017  *                           Germany
00018  *                           Email: cncl-adm@comnets.rwth-aachen.de
00019  *****************************************************************************
00020  * This file is part of the CN class library. All files marked with
00021  * this header are free software; you can redistribute it and/or modify
00022  * it under the terms of the GNU Library General Public License as
00023  * published by the Free Software Foundation; either version 2 of the
00024  * License, or (at your option) any later version.  This library is
00025  * distributed in the hope that it will be useful, but WITHOUT ANY
00026  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00028  * License for more details.  You should have received a copy of the GNU
00029  * Library General Public License along with this library; if not, write
00030  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
00031  * USA.
00032  *****************************************************************************/
00033 
00034 #ifndef __HashStatic_h
00035 #define __HashStatic_h
00036 
00037 
00038 #include <CNCL/Class.h>
00039 #include <CNCL/Param.h>
00040 
00041 #include <CNCL/HashTable.h>             // Base class
00042 
00043 extern CNClassDesc CN_HASHSTATIC;       // CNClass CNHashStatic description
00044 
00048 class CNHashStatic : public CNHashTable
00049 {
00050     struct HashEntry *table;
00051     unsigned long capacity;
00052     unsigned long entries;
00053 
00054 protected:
00055     friend class CNHashIterator;
00057     struct HashEntry *HashTable() const {
00058  return table; }
00059 
00060 public:
00066     virtual void store_key(CNKey *k);
00072     virtual void store_key(CNKey &k) 
00073     { store_key(&k); }
00075     virtual CNKey *get_key(const CNKey *k) const;
00077     virtual CNKey *get_key(const CNKey &k) const
00078     { return get_key(&k); }
00080     virtual CNObject *get_object(const CNKey *k) const;
00082     virtual CNObject *get_object(const CNKey &k) const 
00083     { return get_object(&k); }
00084 
00086     virtual bool reset();
00092     virtual bool reset_absolutely();
00098     virtual bool reset_absolutely_w_obj();
00108     virtual bool delete_key(const CNKey *k);
00118     virtual bool delete_key(const CNKey &k) 
00119     { return delete_key(&k); }
00126     virtual bool delete_key_absolutely(const CNKey *k);
00133     virtual bool delete_key_absolutely(const CNKey &k)
00134     { return delete_key_absolutely(&k); }
00141     virtual bool delete_key_absolutely_w_obj(const CNKey *k);
00148     virtual bool delete_key_absolutely_w_obj(const CNKey &k)
00149     { return delete_key_absolutely_w_obj(&k); }
00150 
00153     virtual bool is_full() const 
00154     { return entries == capacity; }
00157     virtual bool is_empty() const
00158     { return !entries; }
00160     virtual unsigned long get_capacity() const 
00161     { return capacity; }
00163     virtual unsigned long get_num_entries() const
00164     { return entries; }
00165     
00166 private:
00167     unsigned long collision(unsigned long hash_value);
00168     void init_table(unsigned long cap);
00169     unsigned long find_key(const CNKey *k, unsigned long hash_value) const;
00170     void hash(CNKey *k, unsigned long hash_value);
00171     bool remove_key(const CNKey *k, rmKeyType remove_absolutely);
00172 
00173     /****** Constructors ******************************************************/
00174 public:
00179     CNHashStatic(unsigned long cap = DEFAULT_HASH_TABLE_CAPACITY);      
00181     CNHashStatic(CNParam *param);
00183     ~CNHashStatic();
00184 
00185     /****** Member functions required by CNCL *********************************/
00186 public:
00187     virtual CNClassDesc class_desc() const      // CNClass description
00188     {
00189         return CN_HASHSTATIC;
00190     };
00191             
00193     virtual bool is_a(CNClassDesc desc) const    
00194     {
00195         return desc == CN_HASHSTATIC ? TRUE : CNHashTable::is_a(desc);
00196     };
00197         
00199     static CNHashStatic *cast_from_object(CNObject *obj)
00200     {
00201 #   ifdef NO_TYPE_CHECK
00202         return (CNHashStatic *)obj;
00203 #   else
00204         return (CNHashStatic *)( !obj || obj->is_a(CN_HASHSTATIC)
00205                ? obj : fatal_type(obj->class_desc(), CN_HASHSTATIC) );
00206 #   endif
00207     }
00208     
00210     static CNObject *new_object(CNParam *param = NIL) 
00211     { return param ? new CNHashStatic(param) : new CNHashStatic; }
00212     
00214     virtual void print(ostream &strm = cout) const;
00216     virtual void dump (ostream &strm = cout) const;
00217 };
00218 
00219 #endif 

Generated on Fri Feb 1 19:53:52 2002 for CNCL by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001