bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/7] libihash: add HURD_IHASH_ITERATE_ITEMS macro


From: Justus Winter
Subject: [PATCH 3/7] libihash: add HURD_IHASH_ITERATE_ITEMS macro
Date: Thu, 5 Sep 2013 18:38:39 +0200

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.
---
 libihash/ihash.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libihash/ihash.h b/libihash/ihash.h
index a4e76dc..3ca5ec3 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);
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]