Crate fasthash_fork

Source
Expand description

A suite of non-cryptographic hash functions for Rust.

§Example

use std::hash::{Hash, Hasher};

use fasthash::{metro, MetroHasher};

fn hash<T: Hash>(t: &T) -> u64 {
    let mut s: MetroHasher = Default::default();
    t.hash(&mut s);
    s.finish()
}

let h = metro::hash64(b"hello world\xff");

assert_eq!(h, hash(&"hello world"));

By default, HashMap uses a hashing algorithm selected to provide resistance against HashDoS attacks. The hashing algorithm can be replaced on a per-HashMap basis using the HashMap::with_hasher or HashMap::with_capacity_and_hasher methods.

It also cowork with HashMap or HashSet, act as a hash function

use std::collections::HashSet;

use fasthash::spooky::Hash128;

let mut set = HashSet::with_hasher(Hash128);
set.insert(2);

Or use RandomState<CityHash64> with a random seed.

use std::collections::HashMap;

use fasthash::{city, RandomState};

let s = RandomState::<city::Hash64>::new();
let mut map = HashMap::with_hasher(s);

assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

Re-exports§

pub use crate::city::Hasher64 as CityHasher;
pub use crate::city::crc::Hasher128 as CityHasherExt;
pub use crate::farm::Hasher128 as FarmHasherExt;
pub use crate::farm::Hasher64 as FarmHasher;
pub use crate::lookup3::Hasher32 as Lookup3Hasher;
pub use crate::metro::crc::Hasher128_1 as MetroHasherExt;
pub use crate::metro::crc::Hasher64_1 as MetroHasher;
pub use crate::mum::Hasher64 as MumHasher;
pub use crate::murmur::Hasher32 as MurmurHasher;
pub use crate::murmur3::Hasher32 as Murmur3Hasher;
pub use crate::murmur2::Hasher64_x64 as Murmur2Hasher;
pub use crate::murmur3::Hasher128_x64 as Murmur3HasherExt;
pub use crate::spooky::Hasher128 as SpookyHasherExt;
pub use crate::spooky::Hasher64 as SpookyHasher;
pub use crate::ahash::Hash64;
pub use crate::t1ha::t1ha0;
pub use crate::t1ha::t1ha1;
pub use crate::t1ha::t1ha2;
pub use crate::t1ha2::Hasher128 as T1haHasherExt;
pub use crate::t1ha2::Hasher128 as T1haHasher;
pub use crate::highway::Hasher64 as HighwayHasher;
pub use crate::highway::Hasher128 as HighwayHasherExt;
pub use crate::sea::Hasher64 as SeaHasher;
pub use crate::wy::Hasher64 as WYHasher;
pub use crate::xx::Hasher64 as XXHasher;

Modules§

ahash
aHash
city
CityHash, a family of hash functions for strings.
farm
FarmHash, a family of hash functions.
highway
HighwayHash
lookup3
Lookup3, non-cryptographic hash.
meow
Meow - A Fast Non-cryptographic Hash
metro
MetroHash, Exceptionally fast and statistically robust hash functions
mum
MumHash, Hashing functions and PRNGs based on them
murmur
Murmur, a suite of non-cryptographic hash functions that was used for hash-based lookups.
murmur2
Murmur2, a suite of non-cryptographic hash functions that was used for hash-based lookups.
murmur3
Murmur3, a suite of non-cryptographic hash functions that was used for hash-based lookups.
sea
SeaHash: A bizarrely fast hash function.
spooky
SpookyHash: a 128-bit noncryptographic hash function
t1ha
Fast Positive Hash, aka “Позитивный Хэш”
wy
wyhash and wyrand are the ideal 64-bit hash function and PRNG respectively:
xx
xxHash - Extremely fast hash algorithm
xxh3
XXH3 is a new hash algorithm, featuring vastly improved speed performance for both small and large inputs.

Structs§

AHasher
A Hasher for hashing an arbitrary stream of bytes.
RandomState
RandomState provides the default state for HashMap or HashSet types.
Seed
Generate hash seeds

Traits§

BufHasher
Hasher in the buffer mode for short key
FastHash
Fast non-cryptographic hash functions
FastHasher
Fast non-cryptographic hasher
Fingerprint
Generate a good, portable, forever-fixed hash value
HasherExt
A trait which represents the ability to hash an arbitrary stream of bytes.
StreamHasher
Hasher in the streaming mode without buffer