Hash distribution
A good hash function spreads similar keys across different buckets. This version uses a rolling multiplication-and-XOR hash instead of simply adding character codes.
A hash table maps a key to a bucket index using a hash function. This simulator resolves collisions with separate chaining: each bucket stores a small list of key–value entries.
Example hash table loaded. Choose an operation.
A good hash function spreads similar keys across different buckets. This version uses a rolling multiplication-and-XOR hash instead of simply adding character codes.
Colliding keys remain in the same bucket as separate entries. Lookup compares keys only inside the calculated bucket.
The load factor is items / capacity. When enabled, the table doubles near 0.75 and reinserts every entry into the new bucket array.
Inserting an existing key changes its value without increasing the item count. Keys are compared with strict string equality.
| Operation | Average | Worst case |
|---|---|---|
| Insert / Update | O(1) | O(n) |
| Lookup | O(1) | O(n) |
| Delete | O(1) | O(n) |
| Resize / Rehash | O(n) | O(n) |
| Space | O(n + m) | O(n + m) |