more implementation of scanalysis...
[model-checker.git] / hashtable.h
index 016d4925215c7158f0dc7267d5c2a6136668850e..c09b3ff3e77f344f1dd3fa8ab0f4685be5801b87 100644 (file)
@@ -12,8 +12,9 @@
 #include "common.h"
 
 /**
- * Hashtable linked node class, for chained storage of hash table conflicts. By
- * default it is snapshotting, but you can pass in your own allocation
+ * @brief HashTable linked node class, for chained storage of hash table conflicts
+ *
+ * By default it is snapshotting, but you can pass in your own allocation
  * functions.
  *
  * @tparam _Key    Type name for the key
@@ -33,8 +34,10 @@ struct hashlistnode {
 };
 
 /**
- * Hashtable class. By default it is snapshotting, but you can pass in your own
- * allocation functions.
+ * @brief A simple, custom hash table
+ *
+ * By default it is snapshotting, but you can pass in your own allocation
+ * functions.
  *
  * @tparam _Key    Type name for the key
  * @tparam _Val    Type name for the values to be stored
@@ -109,7 +112,7 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
 
                unsigned int index = ((_KeyInt)key) >> _Shift;
                do {
-                       index = index & capacitymask;
+                       index &= capacitymask;
                        search = &table[index];
                        if (search->key == key) {
                                search->val = val;
@@ -129,14 +132,13 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
 
                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. */
@@ -145,11 +147,10 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
 
                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 +162,16 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
                struct hashlistnode<_Key, _Val> *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 +182,7 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
 
                        unsigned int index = ((_KeyInt)key) >> _Shift;
                        do {
-                               index = index & capacitymask;
+                               index &= capacitymask;
                                search = &table[index];
                                index++;
                        } while (search->key);
@@ -190,7 +191,7 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
                        search->val = bin->val;
                }
 
-               _free(oldtable);            //Free the memory of the old hash table
+               _free(oldtable);            // Free the memory of the old hash table
        }
 
  private: