summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-06 23:30:39 +0000
committerJunio C Hamano <gitster@pobox.com>2019-10-07 10:20:11 +0900
commit8a973d0bb398d6d83d6c048acecc750d01bd7234 (patch)
treec4987af10c66582df750927a060b13995dafd84a /hashmap.h
parent87571c3f71ba41d89eef5202f8589daa26f984ca (diff)
downloadgit-8a973d0bb398d6d83d6c048acecc750d01bd7234.tar.gz
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>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/hashmap.h b/hashmap.h
index 8d4b3907b4..bc3b10e097 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -349,7 +349,11 @@ void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
* `entry` is the entry to add or replace.
* Returns the replaced entry, or NULL if not found (i.e. the entry was added).
*/
-void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry);
+struct hashmap_entry *hashmap_put(struct hashmap *map,
+ struct hashmap_entry *entry);
+
+#define hashmap_put_entry(map, keyvar, type, member) \
+ container_of_or_null(hashmap_put(map, &(keyvar)->member), type, member)
/*
* Removes a hashmap entry matching the specified key. If the hashmap contains
@@ -358,8 +362,13 @@ void *hashmap_put(struct hashmap *map, struct hashmap_entry *entry);
*
* Argument explanation is the same as in `hashmap_get`.
*/
-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);
+
+#define hashmap_remove_entry(map, keyvar, keydata, type, member) \
+ container_of_or_null(hashmap_remove(map, &(keyvar)->member, keydata), \
+ type, member)
/*
* Returns the `bucket` an entry is stored in.