@@ -15,31 +15,43 @@ extern crate possiblyrandom;
15
15
16
16
#[ cfg( not( feature = "hashbrown" ) ) ]
17
17
mod std_hashtables {
18
- pub use std:: collections:: HashMap ;
19
18
pub use std:: collections:: hash_map:: RandomState ;
19
+ pub use std:: collections:: HashMap ;
20
20
21
- pub ( crate ) use std:: collections:: { HashSet , hash_map } ;
21
+ pub ( crate ) use std:: collections:: { hash_map , HashSet } ;
22
22
23
23
pub ( crate ) type OccupiedHashMapEntry < ' a , K , V > =
24
24
std:: collections:: hash_map:: OccupiedEntry < ' a , K , V > ;
25
25
pub ( crate ) type VacantHashMapEntry < ' a , K , V > =
26
26
std:: collections:: hash_map:: VacantEntry < ' a , K , V > ;
27
27
28
28
/// Builds a new [`HashMap`].
29
- pub fn new_hash_map < K , V > ( ) -> HashMap < K , V > { HashMap :: new ( ) }
29
+ pub fn new_hash_map < K , V > ( ) -> HashMap < K , V > {
30
+ HashMap :: new ( )
31
+ }
30
32
/// Builds a new [`HashMap`] with the given capacity.
31
33
pub fn hash_map_with_capacity < K , V > ( cap : usize ) -> HashMap < K , V > {
32
34
HashMap :: with_capacity ( cap)
33
35
}
34
- pub ( crate ) fn hash_map_from_iter < K : core:: hash:: Hash + Eq , V , I : IntoIterator < Item =( K , V ) > > ( iter : I ) -> HashMap < K , V > {
36
+ pub ( crate ) fn hash_map_from_iter <
37
+ K : core:: hash:: Hash + Eq ,
38
+ V ,
39
+ I : IntoIterator < Item = ( K , V ) > ,
40
+ > (
41
+ iter : I ,
42
+ ) -> HashMap < K , V > {
35
43
HashMap :: from_iter ( iter)
36
44
}
37
45
38
- pub ( crate ) fn new_hash_set < K > ( ) -> HashSet < K > { HashSet :: new ( ) }
46
+ pub ( crate ) fn new_hash_set < K > ( ) -> HashSet < K > {
47
+ HashSet :: new ( )
48
+ }
39
49
pub ( crate ) fn hash_set_with_capacity < K > ( cap : usize ) -> HashSet < K > {
40
50
HashSet :: with_capacity ( cap)
41
51
}
42
- pub ( crate ) fn hash_set_from_iter < K : core:: hash:: Hash + Eq , I : IntoIterator < Item =K > > ( iter : I ) -> HashSet < K > {
52
+ pub ( crate ) fn hash_set_from_iter < K : core:: hash:: Hash + Eq , I : IntoIterator < Item = K > > (
53
+ iter : I ,
54
+ ) -> HashSet < K > {
43
55
HashSet :: from_iter ( iter)
44
56
}
45
57
}
@@ -64,15 +76,17 @@ mod hashbrown_tables {
64
76
/// A simple implementation of [`BuildHasher`] that uses `getrandom` to opportunistically
65
77
/// randomize, if the platform supports it.
66
78
pub struct RandomState {
67
- k0 : u64 , k1 : u64 ,
79
+ k0 : u64 ,
80
+ k1 : u64 ,
68
81
}
69
82
70
83
impl RandomState {
71
84
/// Constructs a new [`RandomState`] which may or may not be random, depending on the
72
85
/// target platform.
73
86
pub fn new ( ) -> RandomState {
74
87
let ( k0, k1) ;
75
- #[ cfg( all( not( fuzzing) , feature = "possiblyrandom" ) ) ] {
88
+ #[ cfg( all( not( fuzzing) , feature = "possiblyrandom" ) ) ]
89
+ {
76
90
let mut keys = [ 0 ; 16 ] ;
77
91
possiblyrandom:: getpossiblyrandom ( & mut keys) ;
78
92
@@ -83,7 +97,8 @@ mod hashbrown_tables {
83
97
k0 = u64:: from_le_bytes ( k0_bytes) ;
84
98
k1 = u64:: from_le_bytes ( k1_bytes) ;
85
99
}
86
- #[ cfg( any( fuzzing, not( feature = "possiblyrandom" ) ) ) ] {
100
+ #[ cfg( any( fuzzing, not( feature = "possiblyrandom" ) ) ) ]
101
+ {
87
102
k0 = 0 ;
88
103
k1 = 0 ;
89
104
}
@@ -92,7 +107,9 @@ mod hashbrown_tables {
92
107
}
93
108
94
109
impl Default for RandomState {
95
- fn default ( ) -> RandomState { RandomState :: new ( ) }
110
+ fn default ( ) -> RandomState {
111
+ RandomState :: new ( )
112
+ }
96
113
}
97
114
98
115
impl BuildHasher for RandomState {
@@ -103,8 +120,8 @@ mod hashbrown_tables {
103
120
}
104
121
}
105
122
106
- pub use hasher:: * ;
107
123
use super :: * ;
124
+ pub use hasher:: * ;
108
125
109
126
/// The HashMap type used in LDK.
110
127
pub type HashMap < K , V > = hashbrown:: HashMap < K , V , RandomState > ;
@@ -123,7 +140,13 @@ mod hashbrown_tables {
123
140
pub fn hash_map_with_capacity < K , V > ( cap : usize ) -> HashMap < K , V > {
124
141
HashMap :: with_capacity_and_hasher ( cap, RandomState :: new ( ) )
125
142
}
126
- pub ( crate ) fn hash_map_from_iter < K : core:: hash:: Hash + Eq , V , I : IntoIterator < Item =( K , V ) > > ( iter : I ) -> HashMap < K , V > {
143
+ pub ( crate ) fn hash_map_from_iter <
144
+ K : core:: hash:: Hash + Eq ,
145
+ V ,
146
+ I : IntoIterator < Item = ( K , V ) > ,
147
+ > (
148
+ iter : I ,
149
+ ) -> HashMap < K , V > {
127
150
let iter = iter. into_iter ( ) ;
128
151
let min_size = iter. size_hint ( ) . 0 ;
129
152
let mut res = HashMap :: with_capacity_and_hasher ( min_size, RandomState :: new ( ) ) ;
@@ -137,7 +160,9 @@ mod hashbrown_tables {
137
160
pub ( crate ) fn hash_set_with_capacity < K > ( cap : usize ) -> HashSet < K > {
138
161
HashSet :: with_capacity_and_hasher ( cap, RandomState :: new ( ) )
139
162
}
140
- pub ( crate ) fn hash_set_from_iter < K : core:: hash:: Hash + Eq , I : IntoIterator < Item =K > > ( iter : I ) -> HashSet < K > {
163
+ pub ( crate ) fn hash_set_from_iter < K : core:: hash:: Hash + Eq , I : IntoIterator < Item = K > > (
164
+ iter : I ,
165
+ ) -> HashSet < K > {
141
166
let iter = iter. into_iter ( ) ;
142
167
let min_size = iter. size_hint ( ) . 0 ;
143
168
let mut res = HashSet :: with_capacity_and_hasher ( min_size, RandomState :: new ( ) ) ;
0 commit comments