]> git.seodisparate.com - UDPConnection/commitdiff
Change HashMap_insert to replace existing same key
authorStephen Seo <seo.disparate@gmail.com>
Mon, 11 Feb 2019 02:39:09 +0000 (11:39 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 11 Feb 2019 02:39:09 +0000 (11:39 +0900)
src/UDPC_HashMap.c
src/UDPC_HashMap.h

index ef09703b8a148baa3ec1665418c99a3f9c60bc42..90d14fc594c3f2ee6c212c8010be37e81b5ee448 100644 (file)
@@ -90,6 +90,8 @@ void* UDPC_HashMap_insert(UDPC_HashMap *hm, uint32_t key, void *data)
         }
     }
 
+    UDPC_HashMap_remove(hm, key);
+
     uint32_t hash = UDPC_HASH32(key) % hm->capacity;
 
     char *temp = malloc(sizeof(uint32_t) + hm->unitSize);
index 3aadd9cca97f5daf26af49254b84b1dbc90b644f..c91caeb0c1458ff470941148ba7a80489dd36e4a 100644 (file)
@@ -46,6 +46,8 @@ void UDPC_HashMap_destroy(UDPC_HashMap *hashMap);
  * Note if size already equals capacity, the hash map's capacity is doubled
  * with UDPC_HashMap_realloc(). realloc requires rehashing of all items which
  * may be costly.
+ * If an item with the same key already exists in the hash map, it will be
+ * replaced.
  * \return Internally managed pointer to inserted data, NULL on fail
  */
 void* UDPC_HashMap_insert(UDPC_HashMap *hm, uint32_t key, void *data);