#hash #positive #hash-functions #platform #cpu #64-bit #t1ah

no-std t1ha

An implementation of the T1AH (Fast Positive Hash) hash function

3 releases

0.1.2 Feb 19, 2024
0.1.1 Feb 19, 2024
0.1.0 Mar 7, 2019

#162 in Algorithms

Download history 3703/week @ 2024-01-02 3414/week @ 2024-01-09 3034/week @ 2024-01-16 3000/week @ 2024-01-23 6009/week @ 2024-01-30 2263/week @ 2024-02-06 2369/week @ 2024-02-13 1839/week @ 2024-02-20 1446/week @ 2024-02-27 1664/week @ 2024-03-05 1059/week @ 2024-03-12 1045/week @ 2024-03-19 1098/week @ 2024-03-26 1210/week @ 2024-04-02 881/week @ 2024-04-09 676/week @ 2024-04-16

4,122 downloads per month
Used in 9 crates (2 directly)

Zlib license

82KB
2K SLoC

rust-t1ha Continuous integration appveyor crate docs

An implementation of the T1HA (Fast Positive Hash) hash function.

Briefly, it is a portable 64-bit hash function:

  • Intended for 64-bit little-endian platforms, predominantly for Elbrus and x86_64, but portable and without penalties it can run on any 64-bit CPU.
  • In most cases up to 15% faster than StadtX hash, xxHash, mum-hash, metro-hash, etc. and all others portable hash-functions (which do not use specific hardware tricks).
  • Provides a set of terraced hash functions.
  • Currently not suitable for cryptography.
  • Licensed under zlib License.

Usage

To include this crate in your program, add the following to your Cargo.toml:

[dependencies]
t1ha = "0.1"

Using t1ha in a HashMap

The T1haHashMap type alias is the easiest way to use the standard library’s HashMap with t1ha.

use t1ha::T1haHashMap;

let mut map = T1haHashMap::default();
map.insert(1, "one");
map.insert(2, "two");

map = T1haHashMap::with_capacity_and_hasher(10, Default::default());
map.insert(1, "one");
map.insert(2, "two");

Note: the standard library’s HashMap::new and HashMap::with_capacity are only implemented for the RandomState hasher, so using Default to get the hasher is the next best option.

Using t1ha in a HashSet

Similarly, T1haHashSet is a type alias for the standard library’s HashSet with `t1ha.

use t1ha::T1haHashSet;

let mut set = T1haHashSet::default();
set.insert(1);
set.insert(2);

set = T1haHashSet::with_capacity_and_hasher(10, Default::default());
set.insert(1);
set.insert(2);

Performance

t1ha can use AES, AVX or AVX2 instructions as hardware acceleration.

Implementation Platform/CPU
t1ha0_ia32aes_avx() x86 with AES-NI and AVX extensions
t1ha0_ia32aes_avx2() x86 with AES-NI and AVX2 extensions
t1ha0_ia32aes_noavx() x86 with AES-NI without AVX extensions
t1ha0_32le() 32-bit little-endian
t1h0a_32be() 32-bit big-endian
t1ha1_le() 64-bit little-endian
t1ha1_be() 64-bit big-endian
t1ha2_atonce() 64-bit little-endian

You could choose the right implementation base on your target_cpu.

$ RUSTFLAGS="-C target-cpu=native" cargo build

Benchmark

rust-t1ha provide a rough performance comparison to other Rust implemenation of non-cryptographic hash functions, you can run the benchmark base on your envrionment and usage scenario.

$ RUSTFLAGS="-C target-cpu=native" cargo bench

Native t1ha Library

rust-t1ha major focus Rust implementation, if you intent to use the origin native t1ha library, please check rust-fasthash project and it's benchmark, which provides a suite of non-cryptographic hash functions from SMHasher.

Dependencies

~170KB