MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/htable/test/run.c:98–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98int main(void)
99{
100 unsigned int i;
101 uintptr_t perfect_bit;
102 struct htable ht;
103 uint64_t val[NUM_VALS];
104 uint64_t dne;
105 void *p;
106 struct htable_iter iter;
107
108 plan_tests(43);
109 for (i = 0; i < NUM_VALS; i++)
110 val[i] = i;
111 dne = i;
112
113 htable_init(&ht, hash, NULL);
114 ok1(htable_count(&ht) == 0);
115 ok1(ht_max(&ht) == 0);
116 ok1(ht.bits == 0);
117
118 /* We cannot find an entry which doesn't exist. */
119 ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));
120
121 /* This should increase it once. */
122 add_vals(&ht, val, 0, 1);
123 ok1(ht.bits == 1);
124 ok1(ht_max(&ht) == 1);
125 ok1(ht.common_mask == -1);
126
127 /* Mask should be set. */
128 ok1(check_mask(&ht, val, 1));
129
130 /* htable_pick should always return that value */
131 ok1(htable_pick(&ht, 0, NULL) == val);
132 ok1(htable_pick(&ht, 1, NULL) == val);
133 ok1(htable_pick(&ht, 0, &iter) == val);
134 ok1(get_raw_ptr(&ht, ht.table[iter.off]) == val);
135
136 /* This should increase it again. */
137 add_vals(&ht, val, 1, 1);
138 ok1(ht.bits == 2);
139 ok1(ht_max(&ht) == 3);
140
141 /* Mask should be set. */
142 ok1(ht.common_mask != 0);
143 ok1(ht.common_mask != -1);
144 ok1(check_mask(&ht, val, 2));
145
146 /* Now do the rest. */
147 add_vals(&ht, val, 2, NUM_VALS - 2);
148
149 /* Find all. */
150 find_vals(&ht, val, NUM_VALS);
151 ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));
152
153 /* Walk once, should get them all. */
154 i = 0;
155 for (p = htable_first(&ht,&iter); p; p = htable_next(&ht, &iter))

Callers

nothing calls this directly

Calls 13

htable_initFunction · 0.85
htable_countFunction · 0.85
ht_maxFunction · 0.85
htable_getFunction · 0.85
get_raw_ptrFunction · 0.85
htable_clearFunction · 0.85
ht_perfect_maskFunction · 0.85
htable_init_sizedFunction · 0.85
hashFunction · 0.70
add_valsFunction · 0.70
check_maskFunction · 0.70
find_valsFunction · 0.70

Tested by

no test coverage detected