遍历 ACL_BINHASH
- 参数
-
void test() { ACL_BINHASH *table = acl_binhash_create(10, 0); ACL_BINHASH_ITER iter; char *value, key[32]; int i;
for (i = 0; i < 100; i++) { value = (char*) acl_mystrdup("value"); snprintf(key, sizeof(key), "key:%d", i); (void) acl_binhash_enter(table, key, strlen(key), value); }
acl_binhash_foreach(iter, table) { printf("%s=%s\n", iter.ptr->key.c_key, iter.ptr->value); if (i == 50) break; }
acl_binhash_free(table, acl_myfree_fn); }
#ifndef ACL_BINHASH_INCLUDE_H
#define ACL_BINHASH_INCLUDE_H
#ifdef __cplusplus
extern "C" {
#endif
};
union {
};
#define ACL_BINHASH_FLAG_KEY_REUSE (1 << 0)
#define ACL_BINHASH_FLAG_SLICE_RTGC_OFF (1 << 1)
#define ACL_BINHASH_FLAG_SLICE1 (1 << 2)
#define ACL_BINHASH_FLAG_SLICE2 (1 << 3)
#define ACL_BINHASH_FLAG_SLICE3 (1 << 4)
#define ACL_BINHASH_STAT_OK 0
#define ACL_BINHASH_STAT_INVAL 1
#define ACL_BINHASH_STAT_DUPLEX_KEY 2
#define ACL_BINHASH_STAT_NO_KEY 3
#define ACL_BINHASH_ITER_KEY(iter) ((iter).ptr->key.c_key)
#define acl_binhash_iter_key ACL_BINHASH_ITER_KEY
#define ACL_BINHASH_ITER_VALUE(iter) ((iter).ptr->value)
#define acl_binhash_iter_value ACL_BINHASH_ITER_VALUE
#if 0
#define ACL_BINHASH_FOREACH(iter, table_ptr) \
if (table_ptr) \
for((iter).size = acl_binhash_size((table_ptr)), (iter).i = 0, \
(iter).h = acl_binhash_data((table_ptr)); (iter).i < (iter).size; (iter).i++) \
for ((iter).ptr = *(iter).h++; (iter).ptr; (iter).ptr = (iter).ptr->next)
#define ACL_BINHASH_FOREACH_REVERSE(iter, table_ptr) \
if (table_ptr) \
for((iter).size = acl_binhash_size((table_ptr)), (iter).i = (iter).size - 1, \
(iter).h = acl_binhash_data((table_ptr)) + (iter).i; (iter).i >= 0; (iter).i--) \
for ((iter).ptr = *(iter).h--; (iter).ptr; (iter).ptr = (iter).ptr->next)
#else
#define ACL_BINHASH_FOREACH(iter, table_ptr) \
if (table_ptr) \
for((void) acl_binhash_iter_head((table_ptr), &iter); \
(iter).ptr; \
(void) acl_binhash_iter_next(&iter))
#define ACL_BINHASH_FOREACH_REVERSE(iter, table_ptr) \
if (table_ptr) \
for((void) acl_binhash_iter_tail((table_ptr), &iter); \
(iter).ptr; \
(void) acl_binhash_iter_prev(&iter))
#endif
#define acl_binhash_foreach ACL_BINHASH_FOREACH
#define acl_binhash_foreach_reverse ACL_BINHASH_FOREACH_REVERSE
#ifdef __cplusplus
}
#endif
#endif