rustc_data_structures/
fx.rs

1use std::hash::BuildHasherDefault;
2
3pub use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet, FxHasher};
4
5pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
6
7pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
8pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
9pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
10pub type IndexOccupiedEntry<'a, K, V> = indexmap::map::OccupiedEntry<'a, K, V>;
11
12pub use indexmap::set::MutableValues;
13
14#[macro_export]
15macro_rules! define_id_collections {
16    ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
17        pub type $map_name<T> = $crate::unord::UnordMap<$key, T>;
18        pub type $set_name = $crate::unord::UnordSet<$key>;
19        pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>;
20    };
21}
22
23#[macro_export]
24macro_rules! define_stable_id_collections {
25    ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
26        pub type $map_name<T> = $crate::fx::FxIndexMap<$key, T>;
27        pub type $set_name = $crate::fx::FxIndexSet<$key>;
28        pub type $entry_name<'a, T> = $crate::fx::IndexEntry<'a, $key, T>;
29    };
30}
31
32pub mod default {
33    use super::{FxBuildHasher, FxHashMap, FxHashSet};
34
35    // FIXME: These two functions will become unnecessary after
36    // <https://github.com/rust-lang/rustc-hash/pull/63> lands and we start using the corresponding
37    // `rustc-hash` version. After that we can use `Default::default()` instead.
38    pub const fn fx_hash_map<K, V>() -> FxHashMap<K, V> {
39        FxHashMap::with_hasher(FxBuildHasher)
40    }
41
42    pub const fn fx_hash_set<V>() -> FxHashSet<V> {
43        FxHashSet::with_hasher(FxBuildHasher)
44    }
45}