| 219 | } |
| 220 | |
| 221 | void 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 | |
| 268 | bool hashTableInsert(hashTable_t * ht, UINT64 value) |
| 269 | { |
no test coverage detected