ref: 8885f7bcf656626baeb0c4bcdf5239aea594efcf
parent: 5334fc334e610b34c781891ea52072067d5f8b88
author: Jakub Kądziołka <[email protected]>
date: Fri Apr 16 09:42:17 EDT 2021
hash_AddElement: return the new node
--- a/include/hashmap.h
+++ b/include/hashmap.h
@@ -29,9 +29,9 @@
* @param map The HashMap to add the element to
* @param key The key with which the element will be stored and retrieved
* @param element The element to add
- * @return True if a collision occurred (for statistics)
+ * @return A pointer to the pointer to the element.
*/
-bool hash_AddElement(HashMap map, char const *key, void *element);
+void **hash_AddElement(HashMap map, char const *key, void *element);
/**
* Replaces an element with an already-present key in a hashmap.
--- a/src/hashmap.c
+++ b/src/hashmap.c
@@ -46,7 +46,7 @@
return hash;
}
-bool hash_AddElement(HashMap map, char const *key, void *element)
+void **hash_AddElement(HashMap map, char const *key, void *element)
{
HashType hashedKey = hash(key);
HalfHashType index = hashedKey;
@@ -61,7 +61,7 @@
newEntry->next = map[index];
map[index] = newEntry;
- return newEntry->next != NULL;
+ return &newEntry->content;
}
bool hash_ReplaceElement(HashMap const map, char const *key, void *element)