Skip to main content

jsonld_syntax/
hash.rs

1//! Workspace-wide hasher selection.
2//!
3//! Default: hashbrown's [`hashbrown::DefaultHashBuilder`] (`FoldHash` on
4//! hashbrown 0.15+). The `ahash` and `gxhash` features each swap in a
5//! different hasher.
6//!
7//! Cargo unifies features across a dependency graph, so two unrelated
8//! dependants asking for different hashers must not break the build: when
9//! both features end up enabled, `gxhash` wins.
10//!
11//! Enabling `ahash` also adds no new dependency: `lasso`, which backs the
12//! [string interner](crate::intern), enables its `ahasher` feature
13//! unconditionally, so `ahash` is compiled either way.
14
15/// Hasher used by the collections of this crate.
16#[cfg(feature = "gxhash")]
17pub type DefaultBuildHasher = gxhash::GxBuildHasher;
18
19/// Hasher used by the collections of this crate.
20#[cfg(all(feature = "ahash", not(feature = "gxhash")))]
21pub type DefaultBuildHasher = ahash::RandomState;
22
23/// Hasher used by the collections of this crate.
24#[cfg(not(any(feature = "ahash", feature = "gxhash")))]
25pub type DefaultBuildHasher = hashbrown::DefaultHashBuilder;
26
27/// Hash map using [`DefaultBuildHasher`].
28pub type HashMap<K, V, S = DefaultBuildHasher> = hashbrown::HashMap<K, V, S>;
29
30/// Hash set using [`DefaultBuildHasher`].
31pub type HashSet<T, S = DefaultBuildHasher> = hashbrown::HashSet<T, S>;
32
33/// Insertion-ordered map using [`DefaultBuildHasher`].
34pub type IndexMap<K, V, S = DefaultBuildHasher> = indexmap::IndexMap<K, V, S>;
35
36/// Insertion-ordered set using [`DefaultBuildHasher`].
37pub type IndexSet<T, S = DefaultBuildHasher> = indexmap::IndexSet<T, S>;