From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Stefan Beller <sbeller@google.com>
Subject: [PATCH] hashmap: hashmap_get_next passes through keydata as well
Date: Fri, 12 May 2017 13:02:44 -0700 [thread overview]
Message-ID: <20170512200244.25245-1-sbeller@google.com> (raw)
The 'keydata' may be of value in the underlying compare function to decide
if the given two entries are the same.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
Documentation/technical/api-hashmap.txt | 6 ++++--
diffcore-rename.c | 2 +-
hashmap.c | 5 +++--
hashmap.h | 3 ++-
name-hash.c | 2 +-
t/helper/test-hashmap.c | 2 +-
6 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/Documentation/technical/api-hashmap.txt b/Documentation/technical/api-hashmap.txt
index ccc634bbd7..343f1660a9 100644
--- a/Documentation/technical/api-hashmap.txt
+++ b/Documentation/technical/api-hashmap.txt
@@ -140,11 +140,11 @@ to `hashmap_cmp_fn` to decide whether the entry matches the key.
`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
+`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)`::
+`void *hashmap_get_next(const struct hashmap *map, const void *entry, const void *keydata)`::
Returns the next equal hashmap entry, or NULL if not found. This can be
used to iterate over duplicate entries (see `hashmap_add`).
@@ -153,6 +153,8 @@ should not be used in the comparison.
+
`entry` is the hashmap_entry to start the search from, obtained via a previous
call to `hashmap_get` or `hashmap_get_next`.
++
+`keydata` is passed to `hashmap_cmp_fn` to decide whether the entry matches the key.
`void hashmap_add(struct hashmap *map, void *entry)`::
diff --git a/diffcore-rename.c b/diffcore-rename.c
index f7444c86bd..0007fcba23 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -280,7 +280,7 @@ static int find_identical_files(struct hashmap *srcs,
* Find the best source match for specified destination.
*/
p = hashmap_get_from_hash(srcs, hash_filespec(target), NULL);
- for (; p; p = hashmap_get_next(srcs, p)) {
+ for (; p; p = hashmap_get_next(srcs, p, NULL)) {
int score;
struct diff_filespec *source = p->filespec;
diff --git a/hashmap.c b/hashmap.c
index 7d1044eb5d..f144d2fc04 100644
--- a/hashmap.c
+++ b/hashmap.c
@@ -182,11 +182,12 @@ void *hashmap_get(const struct hashmap *map, const void *key, const void *keydat
return *find_entry_ptr(map, key, keydata);
}
-void *hashmap_get_next(const struct hashmap *map, const void *entry)
+void *hashmap_get_next(const struct hashmap *map, const void *entry,
+ const void *keydata)
{
struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next;
for (; e; e = e->next)
- if (entry_equals(map, entry, e, NULL))
+ if (entry_equals(map, entry, e, keydata))
return e;
return NULL;
}
diff --git a/hashmap.h b/hashmap.h
index de6022a3a9..536c53a8ab 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -64,7 +64,8 @@ static inline void hashmap_entry_init(void *entry, unsigned int hash)
}
extern void *hashmap_get(const struct hashmap *map, const void *key,
const void *keydata);
-extern void *hashmap_get_next(const struct hashmap *map, const void *entry);
+extern void *hashmap_get_next(const struct hashmap *map, const void *entry,
+ const void *keydata);
extern void hashmap_add(struct hashmap *map, void *entry);
extern void *hashmap_put(struct hashmap *map, void *entry);
extern void *hashmap_remove(struct hashmap *map, const void *key,
diff --git a/name-hash.c b/name-hash.c
index 39309efb7f..55758ab232 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -703,7 +703,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
while (ce) {
if (same_name(ce, name, namelen, icase))
return ce;
- ce = hashmap_get_next(&istate->name_hash, ce);
+ ce = hashmap_get_next(&istate->name_hash, ce, NULL);
}
return NULL;
}
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
index 7aa9440e27..fa33b32317 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
@@ -206,7 +206,7 @@ int cmd_main(int argc, const char **argv)
puts("NULL");
while (entry) {
puts(get_value(entry));
- entry = hashmap_get_next(&map, entry);
+ entry = hashmap_get_next(&map, entry, NULL);
}
} else if (!strcmp("remove", cmd) && l1) {
--
2.13.0.18.g183880de0a
next reply other threads:[~2017-05-12 20:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-12 20:02 Stefan Beller [this message]
2017-05-13 8:50 ` [PATCH] hashmap: hashmap_get_next passes through keydata as well Jeff King
2017-05-13 14:06 ` Stefan Beller
2017-05-16 16:13 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170512200244.25245-1-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).