Crates.io | tab-hash |
lib.rs | tab-hash |
version | 0.3.0 |
source | src |
created_at | 2019-04-29 13:38:55.474282 |
updated_at | 2020-02-12 16:39:30.676205 |
description | Simple and twisted tabulation hashing for 32-bit and 64-bit unsigned integers. |
homepage | https://github.com/HenningTimm/rust-tab-hash |
repository | https://github.com/HenningTimm/rust-tab-hash |
max_upload_size | |
id | 130976 |
size | 33,397 |
This crate offers rust implementations of simple and twisted tabulation hashing for 32-bit und 64-bit integer values.
Instatiating Tab32Simple
or Tab32Twisted
(or their 64-bit counterparts) will initialize a table and
create a random hash function from the respective hash family.
The hash values of an integer key is computed by calling its hash
method.
use tab_hash::Tab32Simple;
fn main() {
let keys = vec![0, 8, 15, 47, 11];
let simple = Tab32Simple::new();
for k in keys {
println!("{}", simple.hash(k));
}
}
To reproduce hashes, save the table used by the hash function.
The function can be recreated using the with_table
constructor.
use tab_hash::Tab64Twisted;
fn main() {
let key = 42;
let twisted_1 = Tab64Twisted::new();
let twisted_2 = Tab64Twisted::with_table(twisted_1.get_table());
let twisted_3 = Tab64Twisted::new();
assert_eq!(twisted_1.hash(key), twisted_2.hash(key));
assert_ne!(twisted_1.hash(key), twisted_3.hash(key));
}
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).
This implementation is based on the articles of Mihai Pătraşcu and Mikkel Thorup:
Made all structs serializable and deserializable.