tab-hash - Tabulation Hashing for Rust
This crate offers Rust implementations of simple, twisted, and mixed tabulation hashing for 32-bit and 64-bit integer values.
Instantiating Tab32Simple, Tab32Twisted, or Tab32Mixed (or their 64-bit counterparts) will initialize tables and
create a random hash function from the respective hash family.
The hash value of an integer key is computed by calling its hash method.
Simple tabulation example
use Tab32Simple;
Mixed tabulation example
Tab32Mixed and Tab64Mixed use the same new and hash interface as the
simple and twisted variants:
use ;
To reproduce hashes, save the table used by the hash function.
The function can be recreated using the with_table constructor.
use Tab64Twisted;
Mixed tabulation has two tables. Pass both values returned by get_table to
with_table to recreate the same hash function:
use Tab64Mixed;
Note:
These hash functions do not implement the std::hash::Hasher trait,
since they do not work on arbitrary length byte streams.
The 64-bit version of twisted tabulation hashing (Tab64Twisted) requires 128-bit operations (see here).
Mixed tabulation first derives additional 8-bit characters and then hashes the
original and derived characters together. In the notation from the mixed
tabulation papers, c is the number of input characters and d is the number
of derived characters. The theory allows any fixed d >= 1; larger d reduces
the failure-probability terms in the analysis, at the cost of d extra table
lookups and d extra tables. This crate follows the common implementation
choice d = c: Tab32Mixed performs 4 + 4 table lookups, while Tab64Mixed
performs 8 + 8 table lookups.
Literature:
This implementation is based on the articles of Mihai Pătraşcu, Mikkel Thorup, Søren Dahlgaard, et al.:
- Simple Tabulation Hashing
- Twisted Tabulation Hashing
- Hashing for Statistics over k-Partitions (Mixed Tabulation)
- Fast and Powerful Hashing Using Tabulation
Changelog
Version 0.4.0 [2026-08-03]
- Add mixed tabulation hashing. Thanks @jianshu93
- Updated edition
- Updated dependencies
Version 0.3.0 [2020-02-12]
Made all structs serializable and deserializable.