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

Function htable_init_sized

ccan/ccan/htable/htable.c:107–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107bool htable_init_sized(struct htable *ht,
108 size_t (*rehash)(const void *, void *),
109 void *priv, size_t expect)
110{
111 htable_init(ht, rehash, priv);
112
113 /* Don't go insane with sizing. */
114 for (ht->bits = 1; ht_max(ht) < expect; ht->bits++) {
115 if (ht->bits == 30)
116 break;
117 /* Stop before the allocation size wraps (eg. 32-bit). */
118 if ((sizeof(size_t) << (ht->bits + 1)) == 0)
119 break;
120 }
121
122 ht->table = htable_alloc(ht, sizeof(size_t) << ht->bits);
123 if (!ht->table) {
124 ht->table = &ht->common_bits;
125 ht->bits = 0;
126 return false;
127 }
128 (void)htable_debug(ht, HTABLE_LOC);
129 return true;
130}
131
132void htable_clear(struct htable *ht)
133{

Callers 4

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 2

htable_initFunction · 0.85
ht_maxFunction · 0.85

Tested by 4

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68