hashtable: enforce, document non-zero keys
[model-checker.git] / hashtable.h
index 5b0086f24282393b47cdb15ac9377ba3928b8178..71b05cea015d939d7b2b039c4cea8f81afec8170 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,11 @@ 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. Note that this table does not support 0 (NULL) keys and is
+ * designed primarily with pointer-based keys in mind.
  *
  * @tparam _Key    Type name for the key
  * @tparam _Val    Type name for the values to be stored
@@ -102,6 +106,9 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
 
        /** Put a key value pair into the table. */
        void put(_Key key, _Val val) {
+               /* HashTable cannot handle 0 as a key */
+               ASSERT(key);
+
                if (size > threshold)
                        resize(capacity << 1);
 
@@ -127,6 +134,9 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
        _Val get(_Key key) const {
                struct hashlistnode<_Key, _Val> *search;
 
+               /* HashTable cannot handle 0 as a key */
+               ASSERT(key);
+
                unsigned int index = ((_KeyInt)key) >> _Shift;
                do {
                        index &= capacitymask;
@@ -142,6 +152,9 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void *
        bool contains(_Key key) const {
                struct hashlistnode<_Key, _Val> *search;
 
+               /* HashTable cannot handle 0 as a key */
+               ASSERT(key);
+
                unsigned int index = ((_KeyInt)key) >> _Shift;
                do {
                        index &= capacitymask;