From cdd1eff2eecd1b95fd3b2384b08bfaf18e10b0ef Mon Sep 17 00:00:00 2001 From: Stefano Cossu Date: Fri, 18 Mar 2022 09:43:55 -0700 Subject: [PATCH] Add comment about hashmap_delete. --- hashmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hashmap.c b/hashmap.c index faa88c8..fa21374 100644 --- a/hashmap.c +++ b/hashmap.c @@ -248,7 +248,7 @@ static bool resize(struct hashmap *map, size_t new_cap) { // replaced then it is returned otherwise NULL is returned. This operation // may allocate memory. If the system is unable to allocate additional // memory then NULL is returned and hashmap_oom() returns true. -void *hashmap_set(struct hashmap *map, void *item) { +void *hashmap_set(struct hashmap *map, const void *item) { if (!item) { panic("item is null"); } @@ -419,6 +419,10 @@ bool hashmap_scan(struct hashmap *map, // is NOT a copy of the item stored in the hash map and can be directly // modified. // +// Note that if hashmap_delete() is called on the hashmap being iterated, +// the buckets are rearranged and the iterator must be reset to 0, otherwise +// unexpected results may be returned after deletion. +// // This function has not been tested for thread safety. // // The function returns true if an item was retrieved; false if the end of the