Ignore:
Timestamp:
05/29/18 16:51:14 (6 years ago)
Author:
Maciej Komosinski
Message:

Code formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/hashtable.h

    r286 r793  
    1111{
    1212public:
    13 int hash;
    14 SString key;
    15 void *value;
    16 HashEntry *next;
     13        int hash;
     14        SString key;
     15        void *value;
     16        HashEntry *next;
    1717
    18 HashEntry(int h,const SString& k,void *v):hash(h),key(k),value(v),next(0){}
     18        HashEntry(int h, const SString& k, void *v) :hash(h), key(k), value(v), next(0){}
    1919};
    2020
     
    2323class HashTable
    2424{
    25 friend class HashEntryIterator;
    26 HashEntry **tab;
    27 int size;
    28 int count;
    29 int threshold;
    30 float load;
    31 int sync;
     25        friend class HashEntryIterator;
     26        HashEntry **tab;
     27        int size;
     28        int count;
     29        int threshold;
     30        float load;
     31        int sync;
    3232
    33 int hash(const SString &s);
    34 void rehash(int newsize);
     33        int hash(const SString &s);
     34        void rehash(int newsize);
    3535public:
    3636
    37 HashTable(int initsize,float lo) {init(initsize,lo);}
    38 HashTable(int initsize) {init(initsize,0.75);}
    39 HashTable() {init();}
    40 ~HashTable();
     37        HashTable(int initsize, float lo) { init(initsize, lo); }
     38        HashTable(int initsize) { init(initsize, 0.75); }
     39        HashTable() { init(); }
     40        ~HashTable();
    4141
    42 /** always use init() after clear() ! */
    43 void clear();
    44 void init(int initsize=11,float lo=0.75);
     42        /** always use init() after clear() ! */
     43        void clear();
     44        void init(int initsize = 11, float lo = 0.75);
    4545
    46 int getSize() {return count;}
    47 void* put(const SString& key,void *value);
    48 void* get(const SString& key, int *reallygot=0);
    49 void* remove(const SString& key);
    50 /** can be used inside iteration loop:
    51     for(HashEntryIterator it(hashtable);it;) hashtable.remove(it);
    52     \note iterator is "iterated" to the next entry when the current one is removed (no "it++"!)
    53  */
    54 void* remove(HashEntryIterator& it);
     46        int getSize() { return count; }
     47        void* put(const SString& key, void *value);
     48        void* get(const SString& key, int *reallygot = 0);
     49        void* remove(const SString& key);
     50        /** can be used inside iteration loop:
     51                for(HashEntryIterator it(hashtable);it;) hashtable.remove(it);
     52                \note iterator is "iterated" to the next entry when the current one is removed (no "it++"!)
     53                */
     54        void* remove(HashEntryIterator& it);
    5555
    56 void debugprint();
    57 void getstats(float *);
     56        void debugprint();
     57        void getstats(float *);
    5858};
    5959
    6060/** for(HashEntryIterator it(hashtable);it;it++)
    61       {
    62       ... it->value
    63       ... it->key
    64       }
    65  */
     61          {
     62          ... it->value
     63          ... it->key
     64          }
     65          */
    6666class HashEntryIterator
    6767{
    68 void findNext();
    69   public:
    70 const HashTable *ht;
    71 int hashindex;
    72 HashEntry *entry;
    73 int sync;
    74   HashEntryIterator(const HashTable&t):ht(&t),hashindex(0),entry(t.tab[0]),sync(ht->sync)
    75         {if (!entry) findNext();}
    76   HashEntryIterator() {}
    77 void operator++();
    78 void operator++(int) {operator++();}
    79 HashEntry* operator->() {return entry;}
    80 bool isValid() {return (entry&&(sync==ht->sync))?1:0;}
     68        void findNext();
     69public:
     70        const HashTable *ht;
     71        int hashindex;
     72        HashEntry *entry;
     73        int sync;
     74        HashEntryIterator(const HashTable&t) :ht(&t), hashindex(0), entry(t.tab[0]), sync(ht->sync)
     75        {
     76                if (!entry) findNext();
     77        }
     78        HashEntryIterator() {}
     79        void operator++();
     80        void operator++(int) { operator++(); }
     81        HashEntry* operator->() { return entry; }
     82        bool isValid() { return (entry && (sync == ht->sync)) ? 1 : 0; }
    8183};
    8284
Note: See TracChangeset for help on using the changeset viewer.