@@ -125,9 +125,8 @@ impl<K, V, S> Entries for IndexMap<K, V, S> {
125
125
126
126
impl < K , V , S > fmt:: Debug for IndexMap < K , V , S >
127
127
where
128
- K : fmt:: Debug + Hash + Eq ,
128
+ K : fmt:: Debug ,
129
129
V : fmt:: Debug ,
130
- S : BuildHasher ,
131
130
{
132
131
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
133
132
if cfg ! ( not( feature = "test_debug" ) ) {
@@ -165,10 +164,7 @@ impl<K, V, S> IndexMap<K, V, S> {
165
164
///
166
165
/// Computes in **O(n)** time.
167
166
#[ inline]
168
- pub fn with_capacity_and_hasher ( n : usize , hash_builder : S ) -> Self
169
- where
170
- S : BuildHasher ,
171
- {
167
+ pub fn with_capacity_and_hasher ( n : usize , hash_builder : S ) -> Self {
172
168
if n == 0 {
173
169
IndexMap {
174
170
core : IndexMapCore :: new ( ) ,
@@ -182,6 +178,21 @@ impl<K, V, S> IndexMap<K, V, S> {
182
178
}
183
179
}
184
180
181
+ /// Create a new map with `hash_builder`
182
+ pub fn with_hasher ( hash_builder : S ) -> Self {
183
+ Self :: with_capacity_and_hasher ( 0 , hash_builder)
184
+ }
185
+
186
+ /// Computes in **O(1)** time.
187
+ pub fn capacity ( & self ) -> usize {
188
+ self . core . capacity ( )
189
+ }
190
+
191
+ /// Return a reference to the map's `BuildHasher`.
192
+ pub fn hasher ( & self ) -> & S {
193
+ & self . hash_builder
194
+ }
195
+
185
196
/// Return the number of key-value pairs in the map.
186
197
///
187
198
/// Computes in **O(1)** time.
@@ -198,40 +209,63 @@ impl<K, V, S> IndexMap<K, V, S> {
198
209
self . len ( ) == 0
199
210
}
200
211
201
- /// Create a new map with `hash_builder`
202
- pub fn with_hasher ( hash_builder : S ) -> Self
203
- where
204
- S : BuildHasher ,
205
- {
206
- Self :: with_capacity_and_hasher ( 0 , hash_builder)
212
+ /// Return an iterator over the key-value pairs of the map, in their order
213
+ pub fn iter ( & self ) -> Iter < ' _ , K , V > {
214
+ Iter {
215
+ iter : self . as_entries ( ) . iter ( ) ,
216
+ }
207
217
}
208
218
209
- /// Return a reference to the map's `BuildHasher`.
210
- pub fn hasher ( & self ) -> & S
211
- where
212
- S : BuildHasher ,
213
- {
214
- & self . hash_builder
219
+ /// Return an iterator over the key-value pairs of the map, in their order
220
+ pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
221
+ IterMut {
222
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
223
+ }
215
224
}
216
225
217
- /// Computes in **O(1)** time.
218
- pub fn capacity ( & self ) -> usize {
219
- self . core . capacity ( )
226
+ /// Return an iterator over the keys of the map, in their order
227
+ pub fn keys ( & self ) -> Keys < ' _ , K , V > {
228
+ Keys {
229
+ iter : self . as_entries ( ) . iter ( ) ,
230
+ }
231
+ }
232
+
233
+ /// Return an iterator over the values of the map, in their order
234
+ pub fn values ( & self ) -> Values < ' _ , K , V > {
235
+ Values {
236
+ iter : self . as_entries ( ) . iter ( ) ,
237
+ }
238
+ }
239
+
240
+ /// Return an iterator over mutable references to the the values of the map,
241
+ /// in their order
242
+ pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
243
+ ValuesMut {
244
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
245
+ }
220
246
}
221
- }
222
247
223
- impl < K , V , S > IndexMap < K , V , S >
224
- where
225
- K : Hash + Eq ,
226
- S : BuildHasher ,
227
- {
228
248
/// Remove all key-value pairs in the map, while preserving its capacity.
229
249
///
230
250
/// Computes in **O(n)** time.
231
251
pub fn clear ( & mut self ) {
232
252
self . core . clear ( ) ;
233
253
}
234
254
255
+ /// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
256
+ /// Keeps the allocated memory for reuse.
257
+ pub fn drain ( & mut self , range : RangeFull ) -> Drain < ' _ , K , V > {
258
+ Drain {
259
+ iter : self . core . drain ( range) ,
260
+ }
261
+ }
262
+ }
263
+
264
+ impl < K , V , S > IndexMap < K , V , S >
265
+ where
266
+ K : Hash + Eq ,
267
+ S : BuildHasher ,
268
+ {
235
269
/// Reserve capacity for `additional` more key-value pairs.
236
270
///
237
271
/// Computes in **O(n)** time.
@@ -296,42 +330,6 @@ where
296
330
self . core . entry ( hash, key)
297
331
}
298
332
299
- /// Return an iterator over the key-value pairs of the map, in their order
300
- pub fn iter ( & self ) -> Iter < ' _ , K , V > {
301
- Iter {
302
- iter : self . as_entries ( ) . iter ( ) ,
303
- }
304
- }
305
-
306
- /// Return an iterator over the key-value pairs of the map, in their order
307
- pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
308
- IterMut {
309
- iter : self . as_entries_mut ( ) . iter_mut ( ) ,
310
- }
311
- }
312
-
313
- /// Return an iterator over the keys of the map, in their order
314
- pub fn keys ( & self ) -> Keys < ' _ , K , V > {
315
- Keys {
316
- iter : self . as_entries ( ) . iter ( ) ,
317
- }
318
- }
319
-
320
- /// Return an iterator over the values of the map, in their order
321
- pub fn values ( & self ) -> Values < ' _ , K , V > {
322
- Values {
323
- iter : self . as_entries ( ) . iter ( ) ,
324
- }
325
- }
326
-
327
- /// Return an iterator over mutable references to the the values of the map,
328
- /// in their order
329
- pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
330
- ValuesMut {
331
- iter : self . as_entries_mut ( ) . iter_mut ( ) ,
332
- }
333
- }
334
-
335
333
/// Return `true` if an equivalent to `key` exists in the map.
336
334
///
337
335
/// Computes in **O(1)** time (average).
@@ -660,14 +658,6 @@ where
660
658
pub fn reverse ( & mut self ) {
661
659
self . core . reverse ( )
662
660
}
663
-
664
- /// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
665
- /// Keeps the allocated memory for reuse.
666
- pub fn drain ( & mut self , range : RangeFull ) -> Drain < ' _ , K , V > {
667
- Drain {
668
- iter : self . core . drain ( range) ,
669
- }
670
- }
671
661
}
672
662
673
663
impl < K , V , S > IndexMap < K , V , S > {
@@ -963,35 +953,23 @@ impl<K, V> DoubleEndedIterator for Drain<'_, K, V> {
963
953
double_ended_iterator_methods ! ( Bucket :: key_value) ;
964
954
}
965
955
966
- impl < ' a , K , V , S > IntoIterator for & ' a IndexMap < K , V , S >
967
- where
968
- K : Hash + Eq ,
969
- S : BuildHasher ,
970
- {
956
+ impl < ' a , K , V , S > IntoIterator for & ' a IndexMap < K , V , S > {
971
957
type Item = ( & ' a K , & ' a V ) ;
972
958
type IntoIter = Iter < ' a , K , V > ;
973
959
fn into_iter ( self ) -> Self :: IntoIter {
974
960
self . iter ( )
975
961
}
976
962
}
977
963
978
- impl < ' a , K , V , S > IntoIterator for & ' a mut IndexMap < K , V , S >
979
- where
980
- K : Hash + Eq ,
981
- S : BuildHasher ,
982
- {
964
+ impl < ' a , K , V , S > IntoIterator for & ' a mut IndexMap < K , V , S > {
983
965
type Item = ( & ' a K , & ' a mut V ) ;
984
966
type IntoIter = IterMut < ' a , K , V > ;
985
967
fn into_iter ( self ) -> Self :: IntoIter {
986
968
self . iter_mut ( )
987
969
}
988
970
}
989
971
990
- impl < K , V , S > IntoIterator for IndexMap < K , V , S >
991
- where
992
- K : Hash + Eq ,
993
- S : BuildHasher ,
994
- {
972
+ impl < K , V , S > IntoIterator for IndexMap < K , V , S > {
995
973
type Item = ( K , V ) ;
996
974
type IntoIter = IntoIter < K , V > ;
997
975
fn into_iter ( self ) -> Self :: IntoIter {
@@ -1099,7 +1077,7 @@ where
1099
1077
1100
1078
impl < K , V , S > Default for IndexMap < K , V , S >
1101
1079
where
1102
- S : BuildHasher + Default ,
1080
+ S : Default ,
1103
1081
{
1104
1082
/// Return an empty `IndexMap`
1105
1083
fn default ( ) -> Self {
0 commit comments