rapidhash/fast.rs
1//! In-memory hashing: RapidHasher with a focus on speed.
2//!
3//! Designed to maximize hashmap fetch and insert performance on most datasets.
4//!
5//! This is a specific instantiation of the [`crate::inner`] module with the following settings:
6//! - `AVALANCHE` is disabled.
7//! - `SPONGE` is enabled.
8//! - `COMPACT` is disabled, unless building for WASM targets.
9//! - `PROTECTED` is disabled.
10
11const AVALANCHE: bool = false;
12const SPONGE: bool = true;
13const COMPACT: bool = cfg!(target_family = "wasm");
14const PROTECTED: bool = false;
15
16use crate::inner;
17
18/// A [`std::hash::Hasher`] inspired by [`crate::v3::rapidhash_v3`] with a focus on speed and
19/// throughput.
20///
21/// This is an alias for [inner::RapidHasher] with the following settings:
22/// - `AVALANCHE` is disabled.
23/// - `SPONGE` is enabled.
24/// - `COMPACT` is disabled.
25/// - `PROTECTED` is disabled.
26///
27/// Use [`crate::quality::RapidHasher`] for a higher quality hash output where necessary.
28pub type RapidHasher<'s> = inner::RapidHasher<'s, AVALANCHE, SPONGE, COMPACT, PROTECTED>;
29
30/// A rapidhash equivalent to [`std::hash::RandomState`] that uses a random seed and secrets for
31/// minimal DoS resistance.
32///
33/// This initializes a [`crate::quality::RapidHasher`] with the following settings:
34/// - `AVALANCHE` is disabled.
35/// - `SPONGE` is enabled.
36/// - `COMPACT` is disabled.
37/// - `PROTECTED` is disabled.
38///
39/// Use [crate::quality::RandomState] for a higher quality but slower hash output where desirable.
40pub type RandomState = inner::RandomState<AVALANCHE, SPONGE, COMPACT, PROTECTED>;
41
42/// A [`std::hash::BuildHasher`] that uses user-provided seed and secrets.
43///
44/// We recommend using [`RandomState`] or [`GlobalState`] instead for most use cases.
45///
46/// This initializes a [`RapidHasher`] with the following settings:
47/// - `AVALANCHE` is disabled.
48/// - `SPONGE` is enabled.
49/// - `COMPACT` is disabled.
50/// - `PROTECTED` is disabled.
51///
52/// Use [`crate::quality::SeedableState`] for a higher quality but slower hash output where desirable.
53pub type SeedableState<'secrets> = inner::SeedableState<'secrets, AVALANCHE, SPONGE, COMPACT, PROTECTED>;
54
55/// A [`std::hash::BuildHasher`] that uses a global seed and secrets, randomized only once on startup.
56///
57/// All instances of GlobalState will use the same global seed and secrets for the lifetime of the
58/// program. This provides minimal HashDoS resistance by randomizing the seed and secrets between
59/// application runs.
60///
61/// This initializes a [`RapidHasher`] with the following settings:
62/// - `AVALANCHE` is disabled.
63/// - `SPONGE` is enabled.
64/// - `COMPACT` is disabled.
65/// - `PROTECTED` is disabled.
66///
67/// Use [`crate::quality::GlobalState`] for a higher quality but slower hash output where desirable.
68pub type GlobalState = inner::GlobalState<AVALANCHE, SPONGE, COMPACT, PROTECTED>;
69
70#[cfg(any(feature = "std", docsrs))]
71#[deprecated(since = "0.4.0", note = "Please use the top-level rapidhash::RapidHashMap instead")]
72pub use crate::RapidHashMap;
73
74#[cfg(any(feature = "std", docsrs))]
75#[deprecated(since = "0.4.0", note = "Please use the top-level rapidhash::RapidHashSet instead")]
76pub use crate::RapidHashSet;
77
78#[cfg(any(feature = "std", docsrs))]
79#[deprecated(since = "0.4.0", note = "Please use the top-level rapidhash::HashMapExt instead")]
80pub use crate::HashMapExt;
81
82#[cfg(any(feature = "std", docsrs))]
83#[deprecated(since = "0.4.0", note = "Please use the top-level rapidhash::HashSetExt instead")]
84pub use crate::HashSetExt;