A Swiss Table is a form of open-addressed hash table optimized around cache-line-sized groups. The key to having an efficient hash table is the probe sequence, i.e. how to choose in which slot to put keys or how to retrieve them.
Swiss tables break the array into logical groups of 8 slots each. Each group has an associated 64-bit control word where each byte stores the state of one slot:
- empty
- deleted
- in use, in which case it stores , the lower 7 bits of the hash
The complete hash is 64 bit, split as:
- (upper 57 bits): used to select the group
- (lower 7 bits): stored in the control word as a fingerprint
In insertion or lookup, after selecting the group with instead of linear scanning to find the slot, we check the control word first. Since the control word is 64 bits, all 8 slots can be check simultaneously with SIMD. Only if a byte matches then the full key comparison is done.
See Also
- Collisions are unavoidable by Pigeonhole, Chaining and Open Addressing resolve them โ Swiss Table is open addressing with a structured probe sequence; the group is the unit of probing
- Prefer sequential memory access, CPUs predict and prefetch based on locality โ grouping 8 slots together is a deliberate cache line alignment: the control word and its 8 slots fit in one or two cache lines, making probing cache-friendly
- SIMD - one operation applied to multiple data points simulaneously โ the control word check is exactly SIMDโs use case: one instruction, multiple data points checked simultaneously
- False Sharing Forces CPUs to Serialise Access When Two Threads Write to the Same Cache Line โ the control word is the metadata that must be read atomically; concurrent writes to slots in the same group would cause false sharing, which is why Swiss Tables are typically used in single-writer contexts
- A Hash Function Must Be Deterministic, Uniform, and Fast โ FNV-1a Is One Example โ the split of the hash into and requires a hash function whose bits are independently uniform; a poor hash function would cluster values and defeat the SIMD comparison