@@ -8,6 +8,7 @@ use seq_macro::seq;
8
8
use std:: hash:: Hash ;
9
9
use std:: vec;
10
10
11
+ use indexmap:: IndexMap ;
11
12
use micromap:: Map ;
12
13
use rand:: rngs:: SmallRng ;
13
14
use rand:: Rng ;
@@ -36,6 +37,11 @@ fn each_capacity() {
36
37
let hash_map: HashMap <Uuid , [ u8 ; 16 ] > = HashMap :: new( ) ;
37
38
let hashmap_results = for_n:: <N >( hash_map) ;
38
39
assert_eq!( micromap_results, hashmap_results) ;
40
+ // Or use IndexMap instead of HashMap if you want, the final
41
+ // result sequence is consistent.
42
+ // let index_map: IndexMap<Uuid, [u8; 16]> = IndexMap::new();
43
+ // let indexmap_results = for_n::<N>(index_map);
44
+ // assert_eq!(indexmap_results, micromap_results);
39
45
for result in micromap_results {
40
46
let hash_val = make_hash( & result, ROUNDS as u64 ) ;
41
47
xor_hash ^= hash_val;
@@ -135,6 +141,42 @@ where
135
141
}
136
142
}
137
143
144
+ impl < K , V , const N : usize > IsMap < K , V , N > for IndexMap < K , V >
145
+ where
146
+ K : PartialEq + Eq + Hash ,
147
+ {
148
+ fn get ( & self , key : & K ) -> Option < & V > {
149
+ self . get ( key)
150
+ }
151
+
152
+ fn insert ( & mut self , key : K , value : V ) -> Option < V > {
153
+ self . insert ( key, value)
154
+ }
155
+
156
+ fn remove ( & mut self , key : & K ) -> Option < V > {
157
+ self . swap_remove ( key)
158
+ }
159
+
160
+ fn retain < F > ( & mut self , f : F )
161
+ where
162
+ F : FnMut ( & K , & mut V ) -> bool ,
163
+ {
164
+ self . retain ( f)
165
+ }
166
+
167
+ fn len ( & self ) -> usize {
168
+ self . len ( )
169
+ }
170
+
171
+ fn contains_key ( & self , key : & K ) -> bool {
172
+ self . contains_key ( key)
173
+ }
174
+
175
+ fn clear ( & mut self ) {
176
+ self . clear ( )
177
+ }
178
+ }
179
+
138
180
enum MapOp < K , V > {
139
181
Get ( K ) ,
140
182
Insert ( K , V ) ,
0 commit comments