commit-hurd
[Top][All Lists]
Advanced

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

[hurd] 51/70: libihash: add HURD_IHASH_ITERATE_ITEMS macro


From: Samuel Thibault
Subject: [hurd] 51/70: libihash: add HURD_IHASH_ITERATE_ITEMS macro
Date: Mon, 16 Sep 2013 07:41:44 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 39e97c785a7b7f5fd5458986aa834e4069ce3b2f
Author: Justus Winter <address@hidden>
Date:   Thu Sep 5 18:38:39 2013 +0200

    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.
---
 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

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