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

Function double_table

ccan/ccan/htable/htable.c:316–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316static COLD bool double_table(struct htable *ht)
317{
318 unsigned int i;
319 size_t oldnum = ht_size(ht);
320 size_t newsize = sizeof(size_t) << (ht->bits+1);
321 uintptr_t *oldtable, e;
322
323 /* 32-bit: doubling can wrap the allocation size to 0. */
324 if (newsize == 0)
325 return false;
326
327 oldtable = ht->table;
328 ht->table = htable_alloc(ht, newsize);
329 if (!ht->table) {
330 ht->table = oldtable;
331 return false;
332 }
333 ht->bits++;
334
335 /* If we lost our "perfect bit", get it back now. */
336 if (ht->perfect_bitnum == NO_PERFECT_BIT && ht->common_mask) {
337 for (i = 0; i < sizeof(ht->common_mask) * CHAR_BIT; i++) {
338 if (ht->common_mask & ((size_t)2 << i)) {
339 ht->perfect_bitnum = i;
340 break;
341 }
342 }
343 }
344
345 if (oldtable != &ht->common_bits) {
346 for (i = 0; i < oldnum; i++) {
347 if (entry_is_valid(e = oldtable[i])) {
348 void *p = get_raw_ptr(ht, e);
349 ht_add(ht, p, ht->rehash(p, ht->priv));
350 }
351 }
352 htable_free(ht, oldtable);
353 }
354 ht->deleted = 0;
355
356 (void)htable_debug(ht, HTABLE_LOC);
357 return true;
358}
359
360static COLD void rehash_table(struct htable *ht)
361{

Callers 1

htable_add_Function · 0.85

Calls 4

ht_sizeFunction · 0.85
entry_is_validFunction · 0.85
get_raw_ptrFunction · 0.85
ht_addFunction · 0.85

Tested by

no test coverage detected