Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-10-07 02:30:38 +0300
committerJunio C Hamano <gitster@pobox.com>2019-10-07 04:20:11 +0300
commit87571c3f71ba41d89eef5202f8589daa26f984ca (patch)
treed3b072917efce49f3f95d7d48763a8dfc83ef211 /hashmap.h
parent939af16eac1608766273d3971598dbcc4fe09928 (diff)
hashmap: use *_entry APIs for iteration
Inspired by list_for_each_entry in the Linux kernel. Once again, these are somewhat compromised usability-wise by compilers lacking __typeof__ support. 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.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/hashmap.h b/hashmap.h
index 8f5c163d56..8d4b3907b4 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -382,16 +382,27 @@ struct hashmap_iter {
void hashmap_iter_init(struct hashmap *map, struct hashmap_iter *iter);
/* Returns the next hashmap_entry, or NULL if there are no more entries. */
-void *hashmap_iter_next(struct hashmap_iter *iter);
+struct hashmap_entry *hashmap_iter_next(struct hashmap_iter *iter);
/* Initializes the iterator and returns the first entry, if any. */
-static inline void *hashmap_iter_first(struct hashmap *map,
+static inline struct hashmap_entry *hashmap_iter_first(struct hashmap *map,
struct hashmap_iter *iter)
{
hashmap_iter_init(map, iter);
return hashmap_iter_next(iter);
}
+#define hashmap_iter_next_entry(iter, type, member) \
+ container_of_or_null(hashmap_iter_next(iter), type, member)
+
+#define hashmap_iter_first_entry(map, iter, type, member) \
+ container_of_or_null(hashmap_iter_first(map, iter), type, member)
+
+#define hashmap_for_each_entry(map, iter, var, type, member) \
+ for (var = hashmap_iter_first_entry(map, iter, type, member); \
+ var; \
+ var = hashmap_iter_next_entry(iter, type, member))
+
/*
* returns a @pointer of @type matching @keyvar, or NULL if nothing found.
* @keyvar is a pointer of @type