• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::fast::{FixedState, RandomState};
2 
3 /// Type alias for [`std::collections::HashMap<K, V, foldhash::fast::RandomState>`].
4 pub type HashMap<K, V> = std::collections::HashMap<K, V, RandomState>;
5 
6 /// Type alias for [`std::collections::HashSet<T, foldhash::fast::RandomState>`].
7 pub type HashSet<T> = std::collections::HashSet<T, RandomState>;
8 
9 /// A convenience extension trait to enable [`HashMap::new`] for hash maps that use `foldhash`.
10 pub trait HashMapExt {
11     /// Creates an empty `HashMap`.
new() -> Self12     fn new() -> Self;
13 
14     /// Creates an empty `HashMap` with at least the specified capacity.
with_capacity(capacity: usize) -> Self15     fn with_capacity(capacity: usize) -> Self;
16 }
17 
18 impl<K, V> HashMapExt for std::collections::HashMap<K, V, RandomState> {
19     #[inline(always)]
new() -> Self20     fn new() -> Self {
21         Self::with_hasher(RandomState::default())
22     }
23 
24     #[inline(always)]
with_capacity(capacity: usize) -> Self25     fn with_capacity(capacity: usize) -> Self {
26         Self::with_capacity_and_hasher(capacity, RandomState::default())
27     }
28 }
29 
30 impl<K, V> HashMapExt for std::collections::HashMap<K, V, FixedState> {
31     #[inline(always)]
new() -> Self32     fn new() -> Self {
33         Self::with_hasher(FixedState::default())
34     }
35 
36     #[inline(always)]
with_capacity(capacity: usize) -> Self37     fn with_capacity(capacity: usize) -> Self {
38         Self::with_capacity_and_hasher(capacity, FixedState::default())
39     }
40 }
41 
42 /// A convenience extension trait to enable [`HashSet::new`] for hash sets that use `foldhash`.
43 pub trait HashSetExt {
44     /// Creates an empty `HashSet`.
new() -> Self45     fn new() -> Self;
46 
47     /// Creates an empty `HashSet` with at least the specified capacity.
with_capacity(capacity: usize) -> Self48     fn with_capacity(capacity: usize) -> Self;
49 }
50 
51 impl<T> HashSetExt for std::collections::HashSet<T, RandomState> {
52     #[inline(always)]
new() -> Self53     fn new() -> Self {
54         Self::with_hasher(RandomState::default())
55     }
56 
57     #[inline(always)]
with_capacity(capacity: usize) -> Self58     fn with_capacity(capacity: usize) -> Self {
59         Self::with_capacity_and_hasher(capacity, RandomState::default())
60     }
61 }
62 
63 impl<T> HashSetExt for std::collections::HashSet<T, FixedState> {
64     #[inline(always)]
new() -> Self65     fn new() -> Self {
66         Self::with_hasher(FixedState::default())
67     }
68 
69     #[inline(always)]
with_capacity(capacity: usize) -> Self70     fn with_capacity(capacity: usize) -> Self {
71         Self::with_capacity_and_hasher(capacity, FixedState::default())
72     }
73 }
74