| 22 | #define HASH_LOAD_LIMIT(size) ((size)*3/4) |
| 23 | |
| 24 | struct hashtable *hashtable_create(int size, int key64) |
| 25 | { |
| 26 | int req = size; |
| 27 | struct hashtable *tbl; |
| 28 | int node_size = key64 ? sizeof (struct ht_int64_node) |
| 29 | : sizeof (struct ht_int32_node); |
| 30 | |
| 31 | /* Pick a power of 2 that can hold the requested size. */ |
| 32 | if (size & (size-1) || size < 16) { |
| 33 | size = 16; |
| 34 | while (size < req) |
| 35 | size *= 2; |
| 36 | } |
| 37 | |
| 38 | tbl = new(struct hashtable); |
| 39 | tbl->nodes = new_array0(char, size * node_size); |
| 40 | tbl->size = size; |
| 41 | tbl->entries = 0; |
| 42 | tbl->node_size = node_size; |
| 43 | tbl->key64 = key64 ? 1 : 0; |
| 44 | |
| 45 | if (DEBUG_GTE(HASH, 1)) { |
| 46 | char buf[32]; |
| 47 | if (req != size) |
| 48 | snprintf(buf, sizeof buf, "req: %d, ", req); |
| 49 | else |
| 50 | *buf = '\0'; |
| 51 | rprintf(FINFO, "[%s] created hashtable %lx (%ssize: %d, keys: %d-bit)\n", |
| 52 | who_am_i(), (long)tbl, buf, size, key64 ? 64 : 32); |
| 53 | } |
| 54 | |
| 55 | return tbl; |
| 56 | } |
| 57 | |
| 58 | void hashtable_destroy(struct hashtable *tbl) |
| 59 | { |
no test coverage detected