ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GHash.hh
(Generate patch)
# Line 11 | Line 11
11   * indexed by a character string (essentially, maps strings to pointers)
12   */
13  
14 typedef struct {
15     char*   key;              // Key string
16     bool    keyalloc;         //shared key flag (to not free the key chars)
17     int     hash;             // Hash value of key
18     pointer data;              // Data
19     bool    mark;             // Entry is marked
20     } GHashEntry;
14  
15 < template <class OBJ> class  GHash {
15 > template <class OBJ> class GHash {
16   protected:
17 +        struct GHashEntry {
18 +             char*   key;              // Key string
19 +             bool    keyalloc;         //shared key flag (to not free the key chars)
20 +             int     hash;             // Hash value of key
21 +             pointer data;              // Data
22 +             bool    mark;             // Entry is marked
23 +             };
24    GHashEntry* hash;         // Hash
25    int         fCapacity;     // table size
26    int         fCount;        // number of valid entries
# Line 53 | Line 53
53   public:
54    static void DefaultFreeProc(pointer item) {
55        delete (OBJ*)item;
56      item=NULL;
56        }
57   public:
58    GHash(GFreeProc* freeProc); // constructs of an empty hash
# Line 80 | Line 79
79    OBJ* Find(const char* ky, char** keyptr=NULL);
80    bool hasKey(const char* ky);
81    char* getLastKey() { return lastkeyptr; }
82 <  const OBJ* operator[](const char* ky) { return Find(ky); }
82 >  OBJ* operator[](const char* ky) { return Find(ky); }
83    void startIterate(); //iterator-like initialization
84    char* NextKey(); //returns next valid key in the table (NULL if no more)
85    OBJ* NextData(); //returns next valid hash[].data
86    OBJ* NextData(char*& nextkey); //returns next valid hash[].data
87                                  //or NULL if no more
88                                  //nextkey is SET to the corresponding key
89 <  GHashEntry* NextEntry(); //returns a pointer to a GHashEntry
90 <
89 >  GHashEntry* NextEntry() { //returns a pointer to a GHashEntry
90 >         register int pos=fCurrentEntry;
91 >         while (pos<fCapacity && hash[pos].hash<0) pos++;
92 >         if (pos==fCapacity) {
93 >                         fCurrentEntry=fCapacity;
94 >                         return NULL;
95 >                         }
96 >                      else {
97 >                         fCurrentEntry=pos+1;
98 >                         return &hash[pos];
99 >                         }
100 >  }
101    /// Clear all entries
102    void Clear();
103  
# Line 444 | Line 453
453  
454   }
455  
447 template <class OBJ> GHashEntry* GHash<OBJ>::NextEntry() {
448 register int pos=fCurrentEntry;
449 while (pos<fCapacity && hash[pos].hash<0) pos++;
450 if (pos==fCapacity) {
451                 fCurrentEntry=fCapacity;
452                 return NULL;
453                 }
454              else {
455                 fCurrentEntry=pos+1;
456                 return &hash[pos];
457                 }
458 }
459
456  
457   // Get first non-empty entry
458   template <class OBJ> int GHash<OBJ>::First() const {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines