1
1
//! Rayon extensions for `HashMap`.
2
2
3
+ use crate :: hash_map:: HashMap ;
3
4
use core:: fmt;
4
5
use core:: hash:: { BuildHasher , Hash } ;
5
- use hash_map:: HashMap ;
6
6
use rayon:: iter:: plumbing:: UnindexedConsumer ;
7
7
use rayon:: iter:: { FromParallelIterator , IntoParallelIterator , ParallelExtend , ParallelIterator } ;
8
8
@@ -15,7 +15,7 @@ use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, Pa
15
15
/// [`par_iter`]: /hashbrown/struct.HashMap.html#method.par_iter
16
16
/// [`HashMap`]: /hashbrown/struct.HashMap.html
17
17
/// [`IntoParallelRefIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefIterator.html
18
- pub struct ParIter < ' a , K : ' a , V : ' a , S : ' a > {
18
+ pub struct ParIter < ' a , K , V , S > {
19
19
map : & ' a HashMap < K , V , S > ,
20
20
}
21
21
@@ -38,17 +38,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParIter<'a, K, V, S> {
38
38
}
39
39
}
40
40
41
- impl < ' a , K , V , S > Clone for ParIter < ' a , K , V , S > {
41
+ impl < K , V , S > Clone for ParIter < ' _ , K , V , S > {
42
42
#[ inline]
43
43
fn clone ( & self ) -> Self {
44
44
ParIter { map : self . map }
45
45
}
46
46
}
47
47
48
- impl < ' a , K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
49
- for ParIter < ' a , K , V , S >
50
- {
51
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
48
+ impl < K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for ParIter < ' _ , K , V , S > {
49
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
52
50
self . map . iter ( ) . fmt ( f)
53
51
}
54
52
}
@@ -60,7 +58,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
60
58
///
61
59
/// [`par_keys`]: /hashbrown/struct.HashMap.html#method.par_keys
62
60
/// [`HashMap`]: /hashbrown/struct.HashMap.html
63
- pub struct ParKeys < ' a , K : ' a , V : ' a , S : ' a > {
61
+ pub struct ParKeys < ' a , K , V , S > {
64
62
map : & ' a HashMap < K , V , S > ,
65
63
}
66
64
@@ -80,15 +78,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParKeys<'a, K, V, S> {
80
78
}
81
79
}
82
80
83
- impl < ' a , K , V , S > Clone for ParKeys < ' a , K , V , S > {
81
+ impl < K , V , S > Clone for ParKeys < ' _ , K , V , S > {
84
82
#[ inline]
85
83
fn clone ( & self ) -> Self {
86
84
ParKeys { map : self . map }
87
85
}
88
86
}
89
87
90
- impl < ' a , K : fmt:: Debug + Eq + Hash , V , S : BuildHasher > fmt:: Debug for ParKeys < ' a , K , V , S > {
91
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
88
+ impl < K : fmt:: Debug + Eq + Hash , V , S : BuildHasher > fmt:: Debug for ParKeys < ' _ , K , V , S > {
89
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
92
90
self . map . keys ( ) . fmt ( f)
93
91
}
94
92
}
@@ -100,7 +98,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V, S: BuildHasher> fmt::Debug for ParKeys<'a
100
98
///
101
99
/// [`par_values`]: /hashbrown/struct.HashMap.html#method.par_values
102
100
/// [`HashMap`]: /hashbrown/struct.HashMap.html
103
- pub struct ParValues < ' a , K : ' a , V : ' a , S : ' a > {
101
+ pub struct ParValues < ' a , K , V , S > {
104
102
map : & ' a HashMap < K , V , S > ,
105
103
}
106
104
@@ -120,15 +118,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParValues<'a, K, V, S>
120
118
}
121
119
}
122
120
123
- impl < ' a , K , V , S > Clone for ParValues < ' a , K , V , S > {
121
+ impl < K , V , S > Clone for ParValues < ' _ , K , V , S > {
124
122
#[ inline]
125
123
fn clone ( & self ) -> Self {
126
124
ParValues { map : self . map }
127
125
}
128
126
}
129
127
130
- impl < ' a , K : Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for ParValues < ' a , K , V , S > {
131
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
128
+ impl < K : Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for ParValues < ' _ , K , V , S > {
129
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
132
130
self . map . values ( ) . fmt ( f)
133
131
}
134
132
}
@@ -142,7 +140,7 @@ impl<'a, K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValues<'
142
140
/// [`par_iter_mut`]: /hashbrown/struct.HashMap.html#method.par_iter_mut
143
141
/// [`HashMap`]: /hashbrown/struct.HashMap.html
144
142
/// [`IntoParallelRefMutIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefMutIterator.html
145
- pub struct ParIterMut < ' a , K : ' a , V : ' a , S : ' a > {
143
+ pub struct ParIterMut < ' a , K , V , S > {
146
144
map : & ' a mut HashMap < K , V , S > ,
147
145
}
148
146
@@ -165,10 +163,10 @@ impl<'a, K: Send + Sync, V: Send, S: Send> ParallelIterator for ParIterMut<'a, K
165
163
}
166
164
}
167
165
168
- impl < ' a , K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
169
- for ParIterMut < ' a , K , V , S >
166
+ impl < K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
167
+ for ParIterMut < ' _ , K , V , S >
170
168
{
171
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
169
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
172
170
self . map . iter ( ) . fmt ( f)
173
171
}
174
172
}
@@ -180,7 +178,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
180
178
///
181
179
/// [`par_values_mut`]: /hashbrown/struct.HashMap.html#method.par_values_mut
182
180
/// [`HashMap`]: /hashbrown/struct.HashMap.html
183
- pub struct ParValuesMut < ' a , K : ' a , V : ' a , S : ' a > {
181
+ pub struct ParValuesMut < ' a , K , V , S > {
184
182
map : & ' a mut HashMap < K , V , S > ,
185
183
}
186
184
@@ -200,8 +198,8 @@ impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParValuesMut<'a, K, V,
200
198
}
201
199
}
202
200
203
- impl < ' a , K : Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for ParValuesMut < ' a , K , V , S > {
204
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
201
+ impl < K : Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for ParValuesMut < ' _ , K , V , S > {
202
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
205
203
self . map . values ( ) . fmt ( f)
206
204
}
207
205
}
@@ -231,10 +229,8 @@ impl<K: Send, V: Send, S: Send> ParallelIterator for IntoParIter<K, V, S> {
231
229
}
232
230
}
233
231
234
- impl < ' a , K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
235
- for IntoParIter < K , V , S >
236
- {
237
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
232
+ impl < K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug for IntoParIter < K , V , S > {
233
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
238
234
self . map . iter ( ) . fmt ( f)
239
235
}
240
236
}
@@ -246,11 +242,11 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
246
242
///
247
243
/// [`par_drain`]: /hashbrown/struct.HashMap.html#method.par_drain
248
244
/// [`HashMap`]: /hashbrown/struct.HashMap.html
249
- pub struct ParDrain < ' a , K : ' a , V : ' a , S : ' a > {
245
+ pub struct ParDrain < ' a , K , V , S > {
250
246
map : & ' a mut HashMap < K , V , S > ,
251
247
}
252
248
253
- impl < ' a , K : Send , V : Send , S : Send > ParallelIterator for ParDrain < ' a , K , V , S > {
249
+ impl < K : Send , V : Send , S : Send > ParallelIterator for ParDrain < ' _ , K , V , S > {
254
250
type Item = ( K , V ) ;
255
251
256
252
#[ inline]
@@ -262,39 +258,39 @@ impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'a, K, V, S> {
262
258
}
263
259
}
264
260
265
- impl < ' a , K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
266
- for ParDrain < ' a , K , V , S >
261
+ impl < K : fmt:: Debug + Eq + Hash , V : fmt:: Debug , S : BuildHasher > fmt:: Debug
262
+ for ParDrain < ' _ , K , V , S >
267
263
{
268
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
264
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
269
265
self . map . iter ( ) . fmt ( f)
270
266
}
271
267
}
272
268
273
269
impl < K : Sync , V : Sync , S : Sync > HashMap < K , V , S > {
274
270
/// Visits (potentially in parallel) immutably borrowed keys in an arbitrary order.
275
271
#[ inline]
276
- pub fn par_keys ( & self ) -> ParKeys < K , V , S > {
272
+ pub fn par_keys ( & self ) -> ParKeys < ' _ , K , V , S > {
277
273
ParKeys { map : self }
278
274
}
279
275
280
276
/// Visits (potentially in parallel) immutably borrowed values in an arbitrary order.
281
277
#[ inline]
282
- pub fn par_values ( & self ) -> ParValues < K , V , S > {
278
+ pub fn par_values ( & self ) -> ParValues < ' _ , K , V , S > {
283
279
ParValues { map : self }
284
280
}
285
281
}
286
282
287
283
impl < K : Send , V : Send , S : Send > HashMap < K , V , S > {
288
284
/// Visits (potentially in parallel) mutably borrowed values in an arbitrary order.
289
285
#[ inline]
290
- pub fn par_values_mut ( & mut self ) -> ParValuesMut < K , V , S > {
286
+ pub fn par_values_mut ( & mut self ) -> ParValuesMut < ' _ , K , V , S > {
291
287
ParValuesMut { map : self }
292
288
}
293
289
294
290
/// Consumes (potentially in parallel) all values in an arbitrary order,
295
291
/// while preserving the map's allocated memory for reuse.
296
292
#[ inline]
297
- pub fn par_drain ( & mut self ) -> ParDrain < K , V , S > {
293
+ pub fn par_drain ( & mut self ) -> ParDrain < ' _ , K , V , S > {
298
294
ParDrain { map : self }
299
295
}
300
296
}
@@ -426,34 +422,34 @@ mod test_par_map {
426
422
427
423
use rayon:: prelude:: * ;
428
424
429
- use hash_map:: HashMap ;
425
+ use crate :: hash_map:: HashMap ;
430
426
431
427
struct Dropable < ' a > {
432
428
k : usize ,
433
429
counter : & ' a AtomicUsize ,
434
430
}
435
431
436
- impl < ' a > Dropable < ' a > {
437
- fn new ( k : usize , counter : & AtomicUsize ) -> Dropable {
432
+ impl Dropable < ' _ > {
433
+ fn new ( k : usize , counter : & AtomicUsize ) -> Dropable < ' _ > {
438
434
counter. fetch_add ( 1 , Ordering :: Relaxed ) ;
439
435
440
436
Dropable { k, counter }
441
437
}
442
438
}
443
439
444
- impl < ' a > Drop for Dropable < ' a > {
440
+ impl Drop for Dropable < ' _ > {
445
441
fn drop ( & mut self ) {
446
442
self . counter . fetch_sub ( 1 , Ordering :: Relaxed ) ;
447
443
}
448
444
}
449
445
450
- impl < ' a > Clone for Dropable < ' a > {
451
- fn clone ( & self ) -> Dropable < ' a > {
446
+ impl Clone for Dropable < ' _ > {
447
+ fn clone ( & self ) -> Self {
452
448
Dropable :: new ( self . k , self . counter )
453
449
}
454
450
}
455
451
456
- impl < ' a > Hash for Dropable < ' a > {
452
+ impl Hash for Dropable < ' _ > {
457
453
fn hash < H > ( & self , state : & mut H )
458
454
where
459
455
H : Hasher ,
@@ -462,13 +458,13 @@ mod test_par_map {
462
458
}
463
459
}
464
460
465
- impl < ' a > PartialEq for Dropable < ' a > {
461
+ impl PartialEq for Dropable < ' _ > {
466
462
fn eq ( & self , other : & Self ) -> bool {
467
463
self . k == other. k
468
464
}
469
465
}
470
466
471
- impl < ' a > Eq for Dropable < ' a > { }
467
+ impl Eq for Dropable < ' _ > { }
472
468
473
469
#[ test]
474
470
fn test_into_iter_drops ( ) {
0 commit comments