summaryrefslogtreecommitdiff
path: root/Documentation/technical/api-hashmap.txt
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2014-07-02 22:22:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-07 20:56:35 (GMT)
commitab73a9d119240b0b908ccb9edd19b8e536ce29b9 (patch)
treed942c8d2777fa05d082819c998d64c7434ccec42 /Documentation/technical/api-hashmap.txt
parentaa420c48eaea5c89946b8753363d09955300133f (diff)
downloadgit-ab73a9d119240b0b908ccb9edd19b8e536ce29b9.zip
git-ab73a9d119240b0b908ccb9edd19b8e536ce29b9.tar.gz
git-ab73a9d119240b0b908ccb9edd19b8e536ce29b9.tar.bz2
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 'Documentation/technical/api-hashmap.txt')
-rw-r--r--Documentation/technical/api-hashmap.txt14
1 files changed, 14 insertions, 0 deletions
diff --git a/Documentation/technical/api-hashmap.txt b/Documentation/technical/api-hashmap.txt
index f07f17d..8ed92a9 100644
--- a/Documentation/technical/api-hashmap.txt
+++ b/Documentation/technical/api-hashmap.txt
@@ -118,6 +118,20 @@ hashmap_entry) that has at least been initialized with the proper hash code
If an entry with matching hash code is found, `key` and `keydata` are passed
to `hashmap_cmp_fn` to decide whether the entry matches the key.
+`void *hashmap_get_from_hash(const struct hashmap *map, unsigned int hash, const void *keydata)`::
+
+ Returns the hashmap entry for the specified hash code and key data,
+ or NULL if not found.
++
+`map` is the hashmap structure.
++
+`hash` is the hash code of the entry to look up.
++
+If an entry with matching hash code is found, `keydata` is passed to
+`hashmap_cmp_fn` to decide whether the entry matches the key. The
+`entry_or_key` parameter points to a bogus hashmap_entry structure that
+should not be used in the comparison.
+
`void *hashmap_get_next(const struct hashmap *map, const void *entry)`::
Returns the next equal hashmap entry, or NULL if not found. This can be