summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorLibravatar Karsten Blees <karsten.blees@gmail.com>2014-07-03 00:22:11 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-07-07 13:56:35 -0700
commitab73a9d119240b0b908ccb9edd19b8e536ce29b9 (patch)
treed942c8d2777fa05d082819c998d64c7434ccec42 /hashmap.h
parenthashmap: improve struct hashmap member documentation (diff)
downloadtgif-ab73a9d119240b0b908ccb9edd19b8e536ce29b9.tar.xz
hashmap: add simplified hashmap_get_from_hash() API
Hashmap entries are typically looked up by just a key. The hashmap_get() API expects an initialized entry structure instead, to support compound keys. This flexibility is currently only needed by find_dir_entry() in name-hash.c (and compat/win32/fscache.c in the msysgit fork). All other (currently five) call sites of hashmap_get() have to set up a near emtpy entry structure, resulting in duplicate code like this: struct hashmap_entry keyentry; hashmap_entry_init(&keyentry, hash(key)); return hashmap_get(map, &keyentry, key); Add a hashmap_get_from_hash() API that allows hashmap lookups by just specifying the key and its hash code, i.e.: return hashmap_get_from_hash(map, hash(key), key); Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/hashmap.h b/hashmap.h
index c51fd0abf7..a8b9e3dc8c 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -68,6 +68,14 @@ extern void *hashmap_put(struct hashmap *map, void *entry);
extern void *hashmap_remove(struct hashmap *map, const void *key,
const void *keydata);
+static inline void *hashmap_get_from_hash(const struct hashmap *map,
+ unsigned int hash, const void *keydata)
+{
+ struct hashmap_entry key;
+ hashmap_entry_init(&key, hash);
+ return hashmap_get(map, &key, keydata);
+}
+
/* hashmap_iter functions */
extern void hashmap_iter_init(struct hashmap *map, struct hashmap_iter *iter);