Made sh_put_ptr() comapre the key additionally to the hash.
authorStephan Soller <stephan.soller@helionweb.de>
Sat, 30 Apr 2016 11:17:18 +0000 (13:17 +0200)
committerStephan Soller <stephan.soller@helionweb.de>
Sat, 30 Apr 2016 11:17:18 +0000 (13:17 +0200)
slim_hash.h

index 452c854..2828221 100644 (file)
@@ -197,25 +197,31 @@ SH_GEN_HASH_DEF(con_list, int32_t, void*)
         hashmap->slots = NULL;                   \
     }                                            \
                                                  \
-    value_t* prefix##_put_ptr(prefix##_p hashmap, key_t key) {                                                                                                                          \
-        /* add the +1 to the capacity doubling to avoid beeing stuck on a capacity of 0 */                                                                                              \
-        if (hashmap->length + hashmap->deleted + 1 > hashmap->capacity * 0.5)                                                                                                           \
-            prefix##_resize(hashmap, (hashmap->capacity + 1) * 2);                                                                                                                      \
-                                                                                                                                                                                        \
-        uint32_t hash = (hash_expr) | SH_SLOT_FILLED;                                                                                                                                   \
-        size_t index = hash % hashmap->capacity;                                                                                                                                        \
-        while ( !(hashmap->slots[index].hash_and_flags == hash || hashmap->slots[index].hash_and_flags == SH_SLOT_FREE || hashmap->slots[index].hash_and_flags == SH_SLOT_DELETED) ) {  \
-            index = (index + 1) % hashmap->capacity;                                                                                                                                    \
-        }                                                                                                                                                                               \
-                                                                                                                                                                                        \
-        if (hashmap->slots[index].hash_and_flags == SH_SLOT_DELETED)                                                                                                                    \
-            hashmap->deleted--;                                                                                                                                                         \
-        hashmap->length++;                                                                                                                                                              \
-        hashmap->slots[index].hash_and_flags = hash;                                                                                                                                    \
-        hashmap->slots[index].key = (key_put_expr);                                                                                                                                     \
-        return &hashmap->slots[index].value;                                                                                                                                            \
-    }                                                                                                                                                                                   \
-                                                                                                                                                                                        \
+    value_t* prefix##_put_ptr(prefix##_p hashmap, key_t key) {                                                                          \
+        /* add the +1 to the capacity doubling to avoid beeing stuck on a capacity of 0 */                                              \
+        if (hashmap->length + hashmap->deleted + 1 > hashmap->capacity * 0.5)                                                           \
+            prefix##_resize(hashmap, (hashmap->capacity + 1) * 2);                                                                      \
+                                                                                                                                        \
+        uint32_t hash = (hash_expr) | SH_SLOT_FILLED;                                                                                   \
+        size_t index = hash % hashmap->capacity;                                                                                        \
+        while ( !(hashmap->slots[index].hash_and_flags == SH_SLOT_FREE || hashmap->slots[index].hash_and_flags == SH_SLOT_DELETED) ) {  \
+            if (hashmap->slots[index].hash_and_flags == hash) {                                                                         \
+                key_t a = hashmap->slots[index].key;                                                                                    \
+                key_t b = key;                                                                                                          \
+                if (key_cmp_expr)                                                                                                       \
+                    break;                                                                                                              \
+            }                                                                                                                           \
+            index = (index + 1) % hashmap->capacity;                                                                                    \
+        }                                                                                                                               \
+                                                                                                                                        \
+        if (hashmap->slots[index].hash_and_flags == SH_SLOT_DELETED)                                                                    \
+            hashmap->deleted--;                                                                                                         \
+        hashmap->length++;                                                                                                              \
+        hashmap->slots[index].hash_and_flags = hash;                                                                                    \
+        hashmap->slots[index].key = (key_put_expr);                                                                                     \
+        return &hashmap->slots[index].value;                                                                                            \
+    }                                                                                                                                   \
+                                                                                                                                        \
     value_t* prefix##_get_ptr(prefix##_p hashmap, key_t key) {               \
         uint32_t hash = (hash_expr) | SH_SLOT_FILLED;                        \
         size_t index = hash % hashmap->capacity;                             \