diff options
author | Eric Wong <e@80x24.org> | 2019-10-06 23:30:34 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-10-07 10:20:10 +0900 |
commit | 6bcbdfb277bdc81b5ad6996b3fb005382a35c2ee (patch) | |
tree | d2c5a170735b75f905cfe0314aec1d6431e6142a /hashmap.h | |
parent | introduce container_of macro (diff) | |
download | tgif-6bcbdfb277bdc81b5ad6996b3fb005382a35c2ee.tar.xz |
hashmap_get_next returns "struct hashmap_entry *"
This is a step towards removing the requirement for
hashmap_entry being the first field 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 | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -55,15 +55,19 @@ * * if (!strcmp("print_all_by_key", action)) { * struct long2string k, *e; + * struct hashmap_entry *ent; * hashmap_entry_init(&k->ent, memhash(&key, sizeof(long))); * k.key = key; * * flags &= ~COMPARE_VALUE; - * e = hashmap_get(&map, &k, NULL); - * if (e) { + * ent = hashmap_get(&map, &k, NULL); + * if (ent) { + * e = container_of(ent, struct long2string, ent); * printf("first: %ld %s\n", e->key, e->value); - * while ((e = hashmap_get_next(&map, e))) + * while ((ent = hashmap_get_next(&map, ent))) { + * e = container_of(ent, struct long2string, ent); * printf("found more: %ld %s\n", e->key, e->value); + * } * } * } * @@ -320,7 +324,7 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map, * `entry` is the hashmap_entry to start the search from, obtained via a previous * call to `hashmap_get` or `hashmap_get_next`. */ -void *hashmap_get_next(const struct hashmap *map, +struct hashmap_entry *hashmap_get_next(const struct hashmap *map, const struct hashmap_entry *entry); /* |