hash.h

Go to the documentation of this file.
00001 
00063 #ifndef ABA_HASH_H
00064 #define ABA_HASH_H
00065 
00066 #include <iostream>
00067 using namespace std;
00068 
00069 class ABA_GLOBAL;
00070 class ABA_STRING;
00071 
00072 #include "abacus/abacusroot.h"
00073 
00074 template<class KeyType,class ItemType> class ABA_HASH;
00075 
00076 #ifdef ABACUS_PARALLEL
00077 class ABA_ID;
00078 #endif
00079 
00080 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX
00081 template <class KeyType, class ItemType>
00082 class  ABA_HASHITEM;
00083 
00084 template <class KeyType, class ItemType>
00085 class  ABA_HASH;
00086 
00087 template <class KeyType, class ItemType>
00088 ostream &operator<< (ostream &out, const ABA_HASHITEM<KeyType, ItemType> &rhs);
00089 
00090 template <class KeyType, class ItemType>
00091 ostream &operator<< (ostream &out, const ABA_HASH<KeyType, ItemType> &hash);
00092 #endif
00093 
00094   template <class KeyType, class ItemType>
00095   class  ABA_HASHITEM :  public ABA_ABACUSROOT  { 
00096     friend class ABA_HASH<KeyType, ItemType>;
00097 
00098     public: 
00099 
00105       ABA_HASHITEM(const KeyType &key, const ItemType &item);
00106 
00107 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX
00108 
00113       friend ostream &operator<< <> (ostream &,
00114                                      const ABA_HASHITEM<KeyType, ItemType> &);
00115 #else
00116 
00121       friend ostream &operator<< (ostream &out,
00122                                      const ABA_HASHITEM<KeyType, ItemType> &rhs);
00123 #endif
00124 
00128       ABA_HASHITEM<KeyType, ItemType> *next();
00129     private: 
00130       KeyType                      key_;
00131       ItemType                     item_;
00132       ABA_HASHITEM<KeyType, ItemType> *next_;
00133   };
00134 
00135 
00136   template <class KeyType, class ItemType>
00137   class  ABA_HASH :  public ABA_ABACUSROOT  { 
00138     public:
00139 
00146       ABA_HASH(ABA_GLOBAL *glob, int size);
00147 
00151       ~ABA_HASH();
00152 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX
00153 
00165       friend ostream &operator<< <> (ostream &out, 
00166                                      const ABA_HASH<KeyType, ItemType> &hash);
00167 #else
00168 
00180       friend ostream &operator<< (ostream &out, 
00181                                      const ABA_HASH<KeyType, ItemType> &hash);
00182 #endif
00183 
00193       void insert(const KeyType &newKey, const ItemType &newItem);
00194 
00202       void overWrite(const KeyType &newKey, const ItemType &newItem);
00203 
00213       ItemType *find(const KeyType &key);
00214 
00225       bool find(const KeyType &key, const ItemType &item);
00226 
00239       ItemType *initializeIteration(const KeyType &key);
00240 
00255       ItemType *next(const KeyType &key);
00257 
00265       int remove(const KeyType &key);
00266 
00277       int remove(const KeyType &key, const ItemType &item);
00278 
00281       int size() const;
00282 
00287       int nCollisions() const;
00288 
00293       void resize(int newSize);
00294 
00295     private: 
00296 
00305       int hf(int key);
00306 
00311       int hf(unsigned key);
00312 
00317       int hf(const ABA_STRING &string);
00318 #ifdef ABACUS_PARALLEL
00319 
00326       int hf(const ABA_ID &id);
00327 #endif
00328 
00331       ABA_GLOBAL *glob_;
00332 
00339       ABA_HASHITEM<KeyType, ItemType> **table_;
00340 
00343       int size_;
00344 
00347       int nCollisions_;
00348 
00355       ABA_HASHITEM<KeyType, ItemType> *iter_;
00356       ABA_HASH(const ABA_HASH &rhs);
00357       ABA_HASH &operator=(const ABA_HASH &rhs);
00358   };
00359 
00360 
00361 
00362 
00363 #include "abacus/hash.inc"
00364 
00365 #endif  // ABA_HASH_H
00366 
00367 

Generated on Tue Aug 14 18:09:53 2007 for ABACUS by  doxygen 1.5.1