Crate fasthash [−] [src]
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::SpookyHash128; let mut set = HashSet::with_hasher(SpookyHash128 {}); set.insert(2);
Or use RandomState<CityHash64>
with a random seed.
use std::collections::HashMap; use fasthash::RandomState; use fasthash::city::CityHash64; let s = RandomState::<CityHash64>::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");
Reexports
pub use city::CityHasher64 as CityHasher; |
pub use city::CityHasherCrc128 as CityHasherExt; |
pub use farm::FarmHasher64 as FarmHasher; |
pub use farm::FarmHasher128 as FarmHasherExt; |
pub use lookup3::Lookup3Hasher; |
pub use metro::MetroHasher64Crc_1 as MetroHasher; |
pub use metro::MetroHasher128Crc_1 as MetroHasherExt; |
pub use mum::MumHasher; |
pub use murmur::MurmurHasher; |
pub use murmur2::Murmur2Hasher_x64_64 as Murmur2Hasher; |
pub use murmur3::Murmur3Hasher_x64_128 as Murmur3Hasher; |
pub use murmur3::Murmur3Hasher_x64_128 as Murmur3HasherExt; |
pub use sea::SeaHasher64 as SeaHasher; |
pub use spooky::SpookyHasher128 as SpookyHasher; |
pub use spooky::SpookyHasher128 as SpookyHasherExt; |
pub use t1ha::T1ha64CrcHasher as T1haHasher; |
pub use xx::XXHasher64 as XXHasher; |
Modules
city |
|
farm |
|
lookup3 |
|
metro |
|
mum |
|
murmur |
|
murmur2 |
|
murmur3 |
|
sea |
|
spooky |
|
t1ha |
Fast Positive Hash, aka "Позитивный Хэш" |
xx |
|
Structs
RandomState |
|
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 |