bug fix...recompute promises of RMW actions at divergence points
[c11tester.git] / hashtable.h
index 84baaba1e90646f8f71f1bb10cd1360e44315a70..8302000b03e9f9946eb064a8c5c61ca1d8f27b44 100644 (file)
@@ -134,7 +134,6 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift=0, void * (*
                        resize(capacity << 1);
 
                struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *ptr = table[(((_KeyInt)key) & mask)>>_Shift];
-               size++;
                struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *search = ptr;
 
                while(search!=NULL) {
@@ -150,15 +149,24 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift=0, void * (*
                newptr->val=val;
                newptr->next=ptr;
                table[(((_KeyInt)key)&mask)>>_Shift]=newptr;
+               size++;
        }
 
-       /** Put a key entry into the table. */
-       _Val * ensureptr(_Key key) {
+       /**
+        * @brief Get a valid pointer to a value corresponding to a given key
+        *
+        * Ensure that key is present in the hash table, then return a pointer
+        * to its value bin. This may require either creating a new bin for
+        * this key (with a default-constructed value) or simply locating and
+        * returning a pointer to an existing value.
+        * @param key The key to check
+        * @return A pointer to the value in the table
+        */
+       _Val * get_safe_ptr(_Key key) {
                if (size > threshold)
                        resize(capacity << 1);
 
                struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *ptr = table[(((_KeyInt)key) & mask)>>_Shift];
-               size++;
                struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *search = ptr;
 
                while(search!=NULL) {
@@ -172,6 +180,7 @@ template<typename _Key, typename _Val, typename _KeyInt, int _Shift=0, void * (*
                newptr->key=key;
                newptr->next=ptr;
                table[(((_KeyInt)key)&mask)>>_Shift]=newptr;
+               size++;
                return &newptr->val;
        }