Browse Source

Add uthash helpers for iterating over hash entries without the need for safe against deletion

master
Con Kolivas 10 years ago
parent
commit
9a1e59637f
  1. 7
      src/uthash.h

7
src/uthash.h

@ -869,14 +869,21 @@ do {
(sizeof(UT_hash_table)) + \ (sizeof(UT_hash_table)) + \
(HASH_BLOOM_BYTELEN))) (HASH_BLOOM_BYTELEN)))
/* HASH_ITERATE and HASH_FOREACH are not safe for deletion */
#define HASH_ITERATE(head,el) HASH_ITERATE2(hh,head,el)
#define HASH_FOREACH(hh,head,el) HASH_ITERATE2(hh,head,el)
#ifdef NO_DECLTYPE #ifdef NO_DECLTYPE
#define HASH_ITER(hh,head,el,tmp) \ #define HASH_ITER(hh,head,el,tmp) \
for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \
el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL))
#define HASH_ITERATE2(hh,head,el) \
for ((el)=(head); ((head)!= NULL); (head)=(head)->hh.next)
#else #else
#define HASH_ITER(hh,head,el,tmp) \ #define HASH_ITER(hh,head,el,tmp) \
for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \
el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL))
#define HASH_ITERATE2(hh,head,el) \
for ((el)=(head); ((head)!= NULL); (head)=DECLTYPE(el)(head)->hh.next)
#endif #endif
/* obtain a count of items in the hash */ /* obtain a count of items in the hash */

Loading…
Cancel
Save