spacetimedb_data_structures/
map.rs1use core::hash::{BuildHasher, BuildHasherDefault};
2use nohash_hasher::BuildNoHashHasher;
3
4pub use hashbrown::Equivalent;
5pub use nohash_hasher::IsEnabled as ValidAsIdentityHash;
6
7pub mod hash_set {
8 pub use super::HashSet;
9 pub use hashbrown::hash_set::*;
10}
11
12pub mod hash_map {
13 pub use super::HashMap;
14 pub use hashbrown::hash_map::*;
15}
16
17pub type DefaultHashBuilder = BuildHasherDefault<ahash::AHasher>;
18pub type HashMap<K, V> = hashbrown::HashMap<K, V, DefaultHashBuilder>;
23pub type HashSet<T> = hashbrown::HashSet<T, DefaultHashBuilder>;
24
25pub type IntMap<K, V> = hashbrown::HashMap<K, V, BuildNoHashHasher<K>>;
28
29pub type IntSet<K> = hashbrown::HashSet<K, BuildNoHashHasher<K>>;
32
33pub trait HashCollectionExt {
34 fn new() -> Self;
36
37 fn with_capacity(capacity: usize) -> Self;
39}
40
41impl<K, V, S: BuildHasher + Default> HashCollectionExt for hashbrown::HashMap<K, V, S> {
42 fn new() -> Self {
43 Self::with_hasher(S::default())
44 }
45
46 fn with_capacity(capacity: usize) -> Self {
47 Self::with_capacity_and_hasher(capacity, S::default())
48 }
49}
50
51impl<K, S: BuildHasher + Default> HashCollectionExt for hashbrown::HashSet<K, S> {
52 fn new() -> Self {
53 Self::with_hasher(S::default())
54 }
55
56 fn with_capacity(capacity: usize) -> Self {
57 Self::with_capacity_and_hasher(capacity, S::default())
58 }
59}