X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=hashtable.h;h=5b0086f24282393b47cdb15ac9377ba3928b8178;hb=d225d983eb6b52f032fcdc54b7dc612cd4e061fb;hp=6bf813520f505bdb6799f9e2e619510df6e1b7ed;hpb=a2877303b3cde1e5635921a73216d9a67e24945e;p=model-checker.git diff --git a/hashtable.h b/hashtable.h index 6bf8135..5b0086f 100644 --- a/hashtable.h +++ b/hashtable.h @@ -109,7 +109,7 @@ template> _Shift; do { - index = index & capacitymask; + index &= capacitymask; search = &table[index]; if (search->key == key) { search->val = val; @@ -124,32 +124,30 @@ template *search; unsigned int index = ((_KeyInt)key) >> _Shift; do { - index = index&capacitymask; + index &= capacitymask; search = &table[index]; - if (search->key == key) { + if (search->key == key) return search->val; - } index++; } while (search->key); - return (_Val) 0; + return (_Val)0; } /** Check whether the table contains a value for the given key. */ - bool contains(_Key key) { + bool contains(_Key key) const { struct hashlistnode<_Key, _Val> *search; unsigned int index = ((_KeyInt)key) >> _Shift; do { - index = index & capacitymask; + index &= capacitymask; search = &table[index]; - if (search->key == key) { + if (search->key == key) return true; - } index++; } while (search->key); return false; @@ -161,16 +159,16 @@ template *newtable; unsigned int oldcapacity = capacity; - if ((newtable = (struct hashlistnode<_Key, _Val> *) _calloc(newsize, sizeof(struct hashlistnode<_Key, _Val>))) == NULL) { - model_print("Calloc error %s %d\n", __FILE__, __LINE__); - exit(-1); + if ((newtable = (struct hashlistnode<_Key, _Val> *)_calloc(newsize, sizeof(struct hashlistnode<_Key, _Val>))) == NULL) { + model_print("calloc error %s %d\n", __FILE__, __LINE__); + exit(EXIT_FAILURE); } - table = newtable; //Update the global hashtable upon resize() + table = newtable; // Update the global hashtable upon resize() capacity = newsize; capacitymask = newsize - 1; - threshold = (unsigned int) (newsize * loadfactor); + threshold = (unsigned int)(newsize * loadfactor); struct hashlistnode<_Key, _Val> *bin = &oldtable[0]; struct hashlistnode<_Key, _Val> *lastbin = &oldtable[oldcapacity]; @@ -181,7 +179,7 @@ template> _Shift; do { - index = index & capacitymask; + index &= capacitymask; search = &table[index]; index++; } while (search->key); @@ -190,7 +188,7 @@ templateval = bin->val; } - _free(oldtable); //Free the memory of the old hash table + _free(oldtable); // Free the memory of the old hash table } private: