Grafalgo
Library of useful data structures and algorithms
|
00001 00010 #ifndef IDSET_H 00011 #define IDSET_H 00012 00013 #include "Adt.h" 00014 #include "HashTbl.h" 00015 #include "SetPair.h" 00016 00017 namespace grafalgo { 00018 00027 class IdMap : public Adt { 00028 public: 00029 IdMap(int); 00030 ~IdMap(); 00031 00032 // common methods 00033 void clear(); 00034 void resize(int); 00035 void expand(int); 00036 void copyFrom(const IdMap&); 00037 00038 // access methods 00039 int firstId() const; 00040 int nextId(int) const; 00041 int size() const; 00042 int getId(uint64_t) const; 00043 uint64_t getKey(int) const; 00044 00045 // define/retrieve/remove (key,id) pairs 00046 int addPair(uint64_t); 00047 int addPair(uint64_t,int); 00048 void dropPair(uint64_t); 00049 00050 // predicates 00051 bool validKey(uint64_t) const; 00052 bool validId(int) const; 00053 00054 // produce readable IdMaps 00055 string& toString(string&) const; 00056 private: 00057 static const int MAXID = (1 << 20)-1; 00058 HashTbl *ht; 00059 SetPair *ids; 00060 00061 void makeSpace(int); 00062 void freeSpace(); 00063 }; 00064 00068 inline int IdMap::firstId() const { return ids->firstIn(); } 00069 00074 inline int IdMap::nextId(int id) const { return ids->nextIn(id); } 00075 00080 inline bool IdMap::validKey(uint64_t key) const { return ht->lookup(key) != 0; } 00081 00086 inline bool IdMap::validId(int id) const { return ids->isIn(id); } 00087 00091 inline int IdMap::size() const { return ids->getNumIn(); } 00092 00098 inline int IdMap::getId(uint64_t key) const { return ht->lookup(key); } 00099 00104 inline uint64_t IdMap::getKey(int id) const { 00105 return (validId(id) ? ht->getKey(id) : 0); 00106 } 00107 00108 } // ends namespace 00109 00110 #endif