hashmap: hashmap_{put,remove} return hashmap_entry *

And add *_entry variants to perform container_of as necessary
to simplify most callers.

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Eric Wong
2019-10-06 23:30:39 +00:00
committed by Junio C Hamano
parent 87571c3f71
commit 8a973d0bb3
6 changed files with 32 additions and 11 deletions

View File

@@ -219,8 +219,9 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry)
}
}
void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
const void *keydata)
struct hashmap_entry *hashmap_remove(struct hashmap *map,
const struct hashmap_entry *key,
const void *keydata)
{
struct hashmap_entry *old;
struct hashmap_entry **e = find_entry_ptr(map, key, keydata);
@@ -242,7 +243,8 @@ void *hashmap_remove(struct hashmap *map, const struct hashmap_entry *key,
return old;
}
void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry)
struct hashmap_entry *hashmap_put(struct hashmap *map,
struct hashmap_entry *entry)
{
struct hashmap_entry *old = hashmap_remove(map, entry, NULL);
hashmap_add(map, entry);