MCPcopy Create free account
hub / github.com/GregoryFaust/samblaster / resizeHashTable

Function resizeHashTable

sbhash.cpp:221–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221void resizeHashTable(hashTable_t * ht)
222{
223 // Find out what size table is next.
224 int newsize = 0;
225 for (int i=0; i<numOfSizes; i++)
226 {
227 if (hashTableSizes[i] == ht->size)
228 {
229 newsize = hashTableSizes[i+1];
230 break;
231 }
232 }
233
234 // Remember the current values array.
235 UINT64 * oldtable = ht->table;
236 int size = ht->size;
237 // Now reinit the hash table with a new table, etc.
238 hashTableInit(ht, newsize);
239 // Now iterate over all values and rehash them into the new table.
240 for (int i=0; i<size; i++)
241 {
242 UINT64 value = oldtable[i];
243 if (isEmpty(value)) continue;
244 if (isValue(value)) {hashTableInsert(ht, unmakeValue(value)); continue;}
245 // We need to iterate through the nodes.
246 hashNode_t * node = makePtr(value);
247 while (true)
248 {
249 for (int j=0; j<HASHNODE_PAYLOAD_SIZE; j++)
250 {
251 value = node->values[j];
252 if (isEmpty(value)) break;
253 hashTableInsert(ht, unmakeValue(value));
254 }
255 if (node->next == NULL) break;
256 node = node->next;
257 }
258 // We need to free up the nodes.
259 // TODO move out of line.
260 node->next = hashNodeFreeList;
261 hashNodeFreeList = makePtr(oldtable[i]);
262 }
263
264 // Free up the oldtable.
265 if (oldtable != NULL) free(oldtable);
266}
267
268bool hashTableInsert(hashTable_t * ht, UINT64 value)
269{

Callers 1

hashTableInsertFunction · 0.85

Calls 6

hashTableInitFunction · 0.85
isEmptyFunction · 0.85
isValueFunction · 0.85
hashTableInsertFunction · 0.85
unmakeValueFunction · 0.85
makePtrFunction · 0.85

Tested by

no test coverage detected