Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/HashSet.h
Go to the documentation of this file.
00001 
00009 #ifndef HASHSET_H
00010 #define HASHSET_H
00011 
00012 #include "Adt.h"
00013 #include "HashTbl.h"
00014 #include "SetPair.h"
00015 
00016 namespace grafalgo {
00017 
00032 class HashSet : public Adt {
00033 public:
00034                 HashSet(int);
00035                 ~HashSet();
00036 
00037         // common methods
00038         void    clear();
00039         void    resize(int);
00040         void    expand(int);
00041         void    copyFrom(const HashSet&);
00042 
00043         int     size() const;
00044         bool    member(int64_t) const;          
00045 
00046         index   first() const;
00047         index   next(index) const;
00048         bool    isValid(index) const;
00049         uint64_t val(index) const;
00050         index   getIndex(int64_t) const;
00051 
00052         index   insert(int64_t); 
00053         void    remove(int64_t);        
00054 
00055         string& toString(string&) const;
00056 private:
00057         static const int BKT_SIZ = 8;   
00058         typedef uint32_t bkt_t[BKT_SIZ]; 
00059 
00060         int     nb;                     
00061         uint32_t bktMsk;                
00062         bkt_t   *bkt;                   
00063         SetPair *ex;                    
00064 
00065         uint32_t hashit(int64_t, int) const;
00066         void    makeSpace(int);
00067         void    freeSpace();
00068 };
00069 
00073 inline int HashSet::size() const { return ex->getNumIn(); }
00074 
00079 inline bool HashSet::member(int64_t e) const { return getIndex(e) != 0; }
00080 
00085 inline index HashSet::first() const { return ex->firstIn(); }
00086 
00091 inline index HashSet::next(index x) const { return ex->nextIn(x); }
00092 
00097 inline bool HashSet::isValid(index x) const { return ex->isIn(x); }
00098 
00103 inline uint64_t HashSet::val(index x) const {
00104         return bkt[(x-1)/BKT_SIZ][(x-1)%BKT_SIZ];
00105 }
00106 
00107 } // ends namespace
00108 
00109 #endif
 All Classes Files Functions Variables Typedefs Friends