diff options
author | Eric Wong <e@80x24.org> | 2019-10-07 02:30:37 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-10-07 04:20:11 +0300 |
commit | 939af16eac1608766273d3971598dbcc4fe09928 (patch) | |
tree | 15abb229ccf6464acd1241fac3db0c45ee7b6bbd /hashmap.h | |
parent | f23a465132a22860684ac66052cf9a954a18e27d (diff) |
hashmap_cmp_fn takes hashmap_entry params
Another step in eliminating the requirement of hashmap_entry
being the first member of a struct.
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.h | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -21,12 +21,16 @@ * #define COMPARE_VALUE 1 * * static int long2string_cmp(const void *hashmap_cmp_fn_data, - * const struct long2string *e1, - * const struct long2string *e2, + * const struct hashmap_entry *eptr, + * const struct hashmap_entry *entry_or_key, * const void *keydata) * { * const char *string = keydata; * unsigned flags = *(unsigned *)hashmap_cmp_fn_data; + * const struct long2string *e1, *e2; + * + * e1 = container_of(eptr, const struct long2string, ent); + * e2 = container_of(entry_or_key, const struct long2string, ent); * * if (flags & COMPARE_VALUE) * return e1->key != e2->key || @@ -41,7 +45,7 @@ * char value[255], action[32]; * unsigned flags = 0; * - * hashmap_init(&map, (hashmap_cmp_fn) long2string_cmp, &flags, 0); + * hashmap_init(&map, long2string_cmp, &flags, 0); * * while (scanf("%s %ld %s", action, &key, value)) { * @@ -172,7 +176,8 @@ struct hashmap_entry { * The `hashmap_cmp_fn_data` entry is the pointer given in the init function. */ typedef int (*hashmap_cmp_fn)(const void *hashmap_cmp_fn_data, - const void *entry, const void *entry_or_key, + const struct hashmap_entry *entry, + const struct hashmap_entry *entry_or_key, const void *keydata); /* |