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

Function double_table

ccan/ccan/htable/htable.c:306–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306static COLD bool double_table(struct htable *ht)
307{
308 unsigned int i;
309 size_t oldnum = (size_t)1 << ht->bits;
310 uintptr_t *oldtable, e;
311
312 oldtable = ht->table;
313 ht->table = htable_alloc(ht, sizeof(size_t) << (ht->bits+1));
314 if (!ht->table) {
315 ht->table = oldtable;
316 return false;
317 }
318 ht->bits++;
319
320 /* If we lost our "perfect bit", get it back now. */
321 if (ht->perfect_bitnum == NO_PERFECT_BIT && ht->common_mask) {
322 for (i = 0; i < sizeof(ht->common_mask) * CHAR_BIT; i++) {
323 if (ht->common_mask & ((size_t)2 << i)) {
324 ht->perfect_bitnum = i;
325 break;
326 }
327 }
328 }
329
330 if (oldtable != &ht->common_bits) {
331 for (i = 0; i < oldnum; i++) {
332 if (entry_is_valid(e = oldtable[i])) {
333 void *p = get_raw_ptr(ht, e);
334 ht_add(ht, p, ht->rehash(p, ht->priv));
335 }
336 }
337 htable_free(ht, oldtable);
338 }
339 ht->deleted = 0;
340
341 (void)htable_debug(ht, HTABLE_LOC);
342 return true;
343}
344
345static COLD void rehash_table(struct htable *ht)
346{

Callers 1

htable_add_Function · 0.85

Calls 3

entry_is_validFunction · 0.85
get_raw_ptrFunction · 0.85
ht_addFunction · 0.85

Tested by

no test coverage detected