summaryrefslogtreecommitdiff
path: root/libihash
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-09-05 18:38:39 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-09-15 23:04:39 +0200
commit39e97c785a7b7f5fd5458986aa834e4069ce3b2f (patch)
treeeb1d3cc99477f230e05f1affc1d5740e4c88c29a /libihash
parentf1f56bbfeb79a4e28b5476008d9cd5306b204fd7 (diff)
libihash: add HURD_IHASH_ITERATE_ITEMS macro
Add a macro HURD_IHASH_ITERATE_ITEMS that iterates over all elements in the hash table making both the key and the value available. * libihash/ihash.h (HURD_IHASH_ITERATE_ITEMS): New macro.
Diffstat (limited to 'libihash')
-rw-r--r--libihash/ihash.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/libihash/ihash.h b/libihash/ihash.h
index a4e76dc4..3ca5ec38 100644
--- a/libihash/ihash.h
+++ b/libihash/ihash.h
@@ -218,6 +218,23 @@ hurd_ihash_value_t hurd_ihash_find (hurd_ihash_t ht, hurd_ihash_key_t key);
(((_hurd_ihash_item_t) _hurd_ihash_valuep) + 1)) \
if (val != _HURD_IHASH_EMPTY && val != _HURD_IHASH_DELETED)
+/* Iterate over all elements in the hash table making both the key and
+ the value available. You use this macro with a block, for example
+ like this:
+
+ HURD_IHASH_ITERATE_ITEMS (ht, item)
+ foo (item->key, item->value);
+
+ The block will be run for every element in the hash table HT. The
+ key and value of the current element is available as ITEM->key and
+ ITEM->value. */
+#define HURD_IHASH_ITERATE_ITEMS(ht, item) \
+ for (_hurd_ihash_item_t item = (ht)->size? &(ht)->items[0]: 0; \
+ (ht)->size && item - &(ht)->items[0] < (ht)->size; \
+ item++) \
+ if (item->value != _HURD_IHASH_EMPTY && \
+ item->value != _HURD_IHASH_DELETED)
+
/* Remove the entry with the key KEY from the hash table HT. If such
an entry was found and removed, 1 is returned, otherwise 0. */
int hurd_ihash_remove (hurd_ihash_t ht, hurd_ihash_key_t key);