Grafalgo
Library of useful data structures and algorithms
|
00001 00010 #ifndef HASHTABLE_H 00011 #define HASHTABLE_H 00012 00013 #include "stdinc.h" 00014 #include "Adt.h" 00015 00016 namespace grafalgo { 00017 00033 class HashTbl : public Adt { 00034 public: 00035 HashTbl(int); 00036 ~HashTbl(); 00037 00038 // common methods 00039 void clear(); 00040 void resize(int); 00041 void expand(int); 00042 void copyFrom(const HashTbl&); 00043 00044 int size() const; 00045 index lookup(uint64_t) const; 00046 uint64_t getKey(index) const; 00047 00048 bool insert(uint64_t, index); 00049 int remove(uint64_t); 00050 00051 string& toString(string&) const; 00052 private: 00053 static const int BKT_SIZ = 8; 00054 static const int MAXVAL = (1 << 20)-1; 00055 int siz; 00056 int nb; 00057 int bktMsk; 00058 int valMsk; 00059 int fpMsk; 00060 00061 typedef uint32_t bkt_t[BKT_SIZ]; 00062 bkt_t *bkt; 00063 uint64_t *keyVec; 00064 00065 void makeSpace(int); 00066 void freeSpace(); 00067 void hashit(uint64_t,int,uint32_t&,uint32_t&) const; 00068 }; 00069 00073 inline int HashTbl::size() const { return siz; } 00074 00080 inline uint64_t HashTbl::getKey(index i) const { return keyVec[i]; } 00081 00082 } // ends namespace 00083 00084 #endif