fasthash_fork/
lib.rs

1//! A suite of non-cryptographic hash functions for Rust.
2//!
3//! # Example
4//!
5//! ```
6//! use std::hash::{Hash, Hasher};
7//!
8//! use fasthash::{metro, MetroHasher};
9//!
10//! fn hash<T: Hash>(t: &T) -> u64 {
11//!     let mut s: MetroHasher = Default::default();
12//!     t.hash(&mut s);
13//!     s.finish()
14//! }
15//!
16//! let h = metro::hash64(b"hello world\xff");
17//!
18//! assert_eq!(h, hash(&"hello world"));
19//! ```
20//!
21//! By default, `HashMap` uses a hashing algorithm selected to
22//! provide resistance against `HashDoS` attacks.
23//! The hashing algorithm can be replaced on a per-`HashMap` basis
24//! using the `HashMap::with_hasher` or
25//! `HashMap::with_capacity_and_hasher` methods.
26//!
27//! It also cowork with `HashMap` or `HashSet`, act as a hash function
28//!
29//! ```
30//! use std::collections::HashSet;
31//!
32//! use fasthash::spooky::Hash128;
33//!
34//! let mut set = HashSet::with_hasher(Hash128);
35//! set.insert(2);
36//! ```
37//!
38//! Or use `RandomState<CityHash64>` with a random seed.
39//!
40//! ```
41//! use std::collections::HashMap;
42//!
43//! use fasthash::{city, RandomState};
44//!
45//! let s = RandomState::<city::Hash64>::new();
46//! let mut map = HashMap::with_hasher(s);
47//!
48//! assert_eq!(map.insert(37, "a"), None);
49//! assert_eq!(map.is_empty(), false);
50//!
51//! map.insert(37, "b");
52//! assert_eq!(map.insert(37, "c"), Some("b"));
53//! assert_eq!(map[&37], "c");
54//! ```
55#![warn(missing_docs)]
56
57#[macro_use]
58extern crate cfg_if;
59extern crate fasthash_sys_fork as ffi;
60
61cfg_if! {
62    if #[cfg(feature = "digest")] {
63        pub extern crate digest;
64
65        pub use crate::hasher::Output;
66    }
67}
68
69#[macro_use]
70mod hasher;
71
72pub use crate::hasher::{
73    BufHasher, FastHash, FastHasher, Fingerprint, HasherExt, RandomState, Seed, StreamHasher,
74};
75
76cfg_if! {
77    if #[cfg(feature = "city")] {
78        pub mod city;
79
80        cfg_if! {
81            if #[cfg(any(feature = "sse42", target_feature = "sse4.2"))] {
82                pub use crate::city::{Hasher64 as CityHasher, crc::Hasher128 as CityHasherExt};
83            } else {
84                pub use city::{Hasher128 as CityHasherExt, Hasher64 as CityHasher};
85            }
86        }
87    }
88}
89
90cfg_if! {
91    if #[cfg(feature = "farm")] {
92        pub mod farm;
93
94        pub use crate::farm::{Hasher128 as FarmHasherExt, Hasher64 as FarmHasher};
95    }
96}
97
98cfg_if! {
99    if #[cfg(feature = "lookup3")] {
100        pub mod lookup3;
101
102        pub use crate::lookup3::Hasher32 as Lookup3Hasher;
103    }
104}
105
106cfg_if! {
107    if #[cfg(all(feature = "metro", feature = "aes"))] {
108        pub mod meow;
109    }
110}
111
112cfg_if! {
113    if #[cfg(feature = "metro")] {
114        pub mod metro;
115
116        cfg_if! {
117            if #[cfg(any(feature = "sse42", target_feature = "sse4.2"))] {
118                pub use crate::metro::{crc::Hasher128_1 as MetroHasherExt, crc::Hasher64_1 as MetroHasher};
119            } else {
120                pub use metro::{Hasher128_1 as MetroHasherExt, Hasher64_1 as MetroHasher};
121            }
122        }
123    }
124}
125
126cfg_if! {
127    if #[cfg(feature = "mum")] {
128        pub mod mum;
129
130        pub use crate::mum::Hasher64 as MumHasher;
131    }
132}
133
134cfg_if! {
135    if #[cfg(feature = "murmur")] {
136        pub mod murmur;
137        pub mod murmur2;
138        pub mod murmur3;
139
140        pub use crate::murmur::Hasher32 as MurmurHasher;
141        pub use crate::murmur3::Hasher32 as Murmur3Hasher;
142
143        cfg_if! {
144            if #[cfg(target_pointer_width = "64")] {
145                pub use crate::murmur2::Hasher64_x64 as Murmur2Hasher;
146                pub use crate::murmur3::Hasher128_x64 as Murmur3HasherExt;
147            } else {
148                pub use murmur2::Hasher64_x86 as Murmur2Hasher;
149                pub use murmur3::Hasher128_x86 as Murmur3HasherExt;
150            }
151        }
152    }
153}
154
155cfg_if! {
156    if #[cfg(feature = "spooky")] {
157        pub mod spooky;
158
159        pub use crate::spooky::{Hasher128 as SpookyHasherExt, Hasher64 as SpookyHasher};
160    }
161}
162
163cfg_if! {
164    if #[cfg(feature = "ahash")] {
165        pub mod ahash;
166
167        pub use crate::ahash::{AHasher, Hash64};
168    }
169}
170
171cfg_if! {
172    if #[cfg(feature = "t1ha")] {
173        pub mod t1ha;
174
175        pub use crate::t1ha::{t1ha0, t1ha1, t1ha2};
176        pub use crate::t1ha2::{Hasher128 as T1haHasherExt, Hasher128 as T1haHasher};
177    }
178}
179
180cfg_if! {
181    if #[cfg(feature = "highway")] {
182        pub mod highway;
183
184        pub use crate::highway::{Hasher64 as HighwayHasher, Hasher128 as HighwayHasherExt};
185    }
186}
187
188cfg_if! {
189    if #[cfg(feature = "seahash")] {
190        pub mod sea;
191
192        #[doc(no_inline)]
193        pub use crate::sea::Hasher64 as SeaHasher;
194    }
195}
196
197cfg_if! {
198    if #[cfg(feature = "wy")] {
199        pub mod wy;
200
201        pub use crate::wy::Hasher64 as WYHasher;
202    }
203}
204
205cfg_if! {
206    if #[cfg(feature = "xx")] {
207        pub mod xx;
208        pub mod xxh3;
209
210        pub use crate::xx::Hasher64 as XXHasher;
211    }
212}