MCPcopy Create free account
hub / github.com/acl-dev/acl / htable_iter

Function htable_iter

lib_acl/samples/iterator/main.c:59–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59static void htable_iter(void)
60{
61 ACL_SLICE_POOL *slice = acl_slice_pool_create(10, 100,
62 ACL_SLICE_FLAG_GC2 | ACL_SLICE_FLAG_RTGC_OFF);
63 ACL_HTABLE *table = acl_htable_create3(10, 0, slice);
64 ACL_HTABLE_ITER iter;
65 char key[32], *value;
66 int i;
67
68 for (i = 0; i < 20; i++) {
69 snprintf(key, sizeof(key), "key: %d", i);
70 value = acl_mymalloc(32);
71 snprintf(value, 32, "value: %d", i);
72 assert(acl_htable_enter(table, key, value));
73 }
74
75 i = 0;
76 printf("\n>>>acl_htable_foreach:\n");
77 acl_htable_foreach(iter, table) {
78 printf("hash i=%d, [%s]=[%s]\n",
79 iter.i, acl_htable_iter_key(iter),
80 (char*) acl_htable_iter_value(iter));
81 i++;
82 }
83
84 printf(">>>total: %d\n", i);
85
86 i = 0;
87 acl_htable_foreach(iter, table) {
88 printf("hash i=%d, [%s]=[%s]\n",
89 iter.i, acl_htable_iter_key(iter),
90 (char*) acl_htable_iter_value(iter));
91 i++;
92 if (i == 5) {
93 printf("i = %d, break now\n", i);
94 break;
95 }
96 }
97
98
99 i = 0;
100 printf("\n>>>acl_htable_foreach_reverse:\n");
101 acl_htable_foreach_reverse(iter, table) {
102 printf("hash i=%d, [%s]=[%s]\n",
103 iter.i, acl_htable_iter_key(iter),
104 (char*) acl_htable_iter_value(iter));
105 i++;
106 }
107
108 printf(">>>total: %d\n", i);
109
110 acl_htable_stat(table);
111 acl_htable_free(table, acl_myfree_fn);
112 acl_slice_pool_destroy(slice);
113}
114
115static void htable_iter2(void)
116{

Callers 1

mainFunction · 0.85

Calls 6

acl_slice_pool_createFunction · 0.85
acl_htable_create3Function · 0.85
acl_htable_enterFunction · 0.85
acl_htable_statFunction · 0.85
acl_htable_freeFunction · 0.85
acl_slice_pool_destroyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…