1
1
use self :: RustcEntry :: * ;
2
2
use crate :: map:: { make_hash, Drain , HashMap , IntoIter , Iter , IterMut } ;
3
- use crate :: raw:: { Bucket , Global , RawTable } ;
3
+ use crate :: raw:: { AllocRef , Bucket , Global , RawTable } ;
4
4
use core:: fmt:: { self , Debug } ;
5
5
use core:: hash:: { BuildHasher , Hash } ;
6
6
use core:: mem;
7
7
8
- impl < K , V , S > HashMap < K , V , S >
8
+ impl < K , V , S , A > HashMap < K , V , S , A >
9
9
where
10
10
K : Eq + Hash ,
11
11
S : BuildHasher ,
12
+ A : AllocRef + Clone ,
12
13
{
13
14
/// Gets the given key's corresponding entry in the map for in-place manipulation.
14
15
///
30
31
/// assert_eq!(letters.get(&'y'), None);
31
32
/// ```
32
33
#[ cfg_attr( feature = "inline-more" , inline) ]
33
- pub fn rustc_entry ( & mut self , key : K ) -> RustcEntry < ' _ , K , V > {
34
+ pub fn rustc_entry ( & mut self , key : K ) -> RustcEntry < ' _ , K , V , A > {
34
35
let hash = make_hash ( & self . hash_builder , & key) ;
35
36
if let Some ( elem) = self . table . find ( hash, |q| q. 0 . eq ( & key) ) {
36
37
RustcEntry :: Occupied ( RustcOccupiedEntry {
@@ -59,15 +60,18 @@ where
59
60
///
60
61
/// [`HashMap`]: struct.HashMap.html
61
62
/// [`entry`]: struct.HashMap.html#method.rustc_entry
62
- pub enum RustcEntry < ' a , K , V > {
63
+ pub enum RustcEntry < ' a , K , V , A = Global >
64
+ where
65
+ A : AllocRef + Clone ,
66
+ {
63
67
/// An occupied entry.
64
- Occupied ( RustcOccupiedEntry < ' a , K , V > ) ,
68
+ Occupied ( RustcOccupiedEntry < ' a , K , V , A > ) ,
65
69
66
70
/// A vacant entry.
67
- Vacant ( RustcVacantEntry < ' a , K , V > ) ,
71
+ Vacant ( RustcVacantEntry < ' a , K , V , A > ) ,
68
72
}
69
73
70
- impl < K : Debug , V : Debug > Debug for RustcEntry < ' _ , K , V > {
74
+ impl < K : Debug , V : Debug , A : AllocRef + Clone > Debug for RustcEntry < ' _ , K , V , A > {
71
75
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
72
76
match * self {
73
77
Vacant ( ref v) => f. debug_tuple ( "Entry" ) . field ( v) . finish ( ) ,
@@ -80,26 +84,31 @@ impl<K: Debug, V: Debug> Debug for RustcEntry<'_, K, V> {
80
84
/// It is part of the [`RustcEntry`] enum.
81
85
///
82
86
/// [`RustcEntry`]: enum.RustcEntry.html
83
- pub struct RustcOccupiedEntry < ' a , K , V > {
87
+ pub struct RustcOccupiedEntry < ' a , K , V , A = Global >
88
+ where
89
+ A : AllocRef + Clone ,
90
+ {
84
91
key : Option < K > ,
85
92
elem : Bucket < ( K , V ) > ,
86
- table : & ' a mut RawTable < ( K , V ) , Global > ,
93
+ table : & ' a mut RawTable < ( K , V ) , A > ,
87
94
}
88
95
89
- unsafe impl < K , V > Send for RustcOccupiedEntry < ' _ , K , V >
96
+ unsafe impl < K , V , A > Send for RustcOccupiedEntry < ' _ , K , V , A >
90
97
where
91
98
K : Send ,
92
99
V : Send ,
100
+ A : AllocRef + Clone + Send ,
93
101
{
94
102
}
95
- unsafe impl < K , V > Sync for RustcOccupiedEntry < ' _ , K , V >
103
+ unsafe impl < K , V , A > Sync for RustcOccupiedEntry < ' _ , K , V , A >
96
104
where
97
105
K : Sync ,
98
106
V : Sync ,
107
+ A : AllocRef + Clone + Sync ,
99
108
{
100
109
}
101
110
102
- impl < K : Debug , V : Debug > Debug for RustcOccupiedEntry < ' _ , K , V > {
111
+ impl < K : Debug , V : Debug , A : AllocRef + Clone > Debug for RustcOccupiedEntry < ' _ , K , V , A > {
103
112
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
104
113
f. debug_struct ( "OccupiedEntry" )
105
114
. field ( "key" , self . key ( ) )
@@ -112,19 +121,22 @@ impl<K: Debug, V: Debug> Debug for RustcOccupiedEntry<'_, K, V> {
112
121
/// It is part of the [`RustcEntry`] enum.
113
122
///
114
123
/// [`RustcEntry`]: enum.RustcEntry.html
115
- pub struct RustcVacantEntry < ' a , K , V > {
124
+ pub struct RustcVacantEntry < ' a , K , V , A = Global >
125
+ where
126
+ A : AllocRef + Clone ,
127
+ {
116
128
hash : u64 ,
117
129
key : K ,
118
- table : & ' a mut RawTable < ( K , V ) , Global > ,
130
+ table : & ' a mut RawTable < ( K , V ) , A > ,
119
131
}
120
132
121
- impl < K : Debug , V > Debug for RustcVacantEntry < ' _ , K , V > {
133
+ impl < K : Debug , V , A : AllocRef + Clone > Debug for RustcVacantEntry < ' _ , K , V , A > {
122
134
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
123
135
f. debug_tuple ( "VacantEntry" ) . field ( self . key ( ) ) . finish ( )
124
136
}
125
137
}
126
138
127
- impl < ' a , K , V > RustcEntry < ' a , K , V > {
139
+ impl < ' a , K , V , A : AllocRef + Clone > RustcEntry < ' a , K , V , A > {
128
140
/// Sets the value of the entry, and returns a RustcOccupiedEntry.
129
141
///
130
142
/// # Examples
@@ -137,7 +149,7 @@ impl<'a, K, V> RustcEntry<'a, K, V> {
137
149
///
138
150
/// assert_eq!(entry.key(), &"horseyland");
139
151
/// ```
140
- pub fn insert ( self , value : V ) -> RustcOccupiedEntry < ' a , K , V > {
152
+ pub fn insert ( self , value : V ) -> RustcOccupiedEntry < ' a , K , V , A > {
141
153
match self {
142
154
Vacant ( entry) => entry. insert_entry ( value) ,
143
155
Occupied ( mut entry) => {
@@ -253,7 +265,7 @@ impl<'a, K, V> RustcEntry<'a, K, V> {
253
265
}
254
266
}
255
267
256
- impl < ' a , K , V : Default > RustcEntry < ' a , K , V > {
268
+ impl < ' a , K , V : Default , A : AllocRef + Clone > RustcEntry < ' a , K , V , A > {
257
269
/// Ensures a value is in the entry by inserting the default value if empty,
258
270
/// and returns a mutable reference to the value in the entry.
259
271
///
@@ -281,7 +293,7 @@ impl<'a, K, V: Default> RustcEntry<'a, K, V> {
281
293
}
282
294
}
283
295
284
- impl < ' a , K , V > RustcOccupiedEntry < ' a , K , V > {
296
+ impl < ' a , K , V , A : AllocRef + Clone > RustcOccupiedEntry < ' a , K , V , A > {
285
297
/// Gets a reference to the key in the entry.
286
298
///
287
299
/// # Examples
@@ -508,7 +520,7 @@ impl<'a, K, V> RustcOccupiedEntry<'a, K, V> {
508
520
}
509
521
}
510
522
511
- impl < ' a , K , V > RustcVacantEntry < ' a , K , V > {
523
+ impl < ' a , K , V , A : AllocRef + Clone > RustcVacantEntry < ' a , K , V , A > {
512
524
/// Gets a reference to the key that would be used when inserting a value
513
525
/// through the `RustcVacantEntry`.
514
526
///
@@ -583,7 +595,7 @@ impl<'a, K, V> RustcVacantEntry<'a, K, V> {
583
595
/// }
584
596
/// ```
585
597
#[ cfg_attr( feature = "inline-more" , inline) ]
586
- pub fn insert_entry ( self , value : V ) -> RustcOccupiedEntry < ' a , K , V > {
598
+ pub fn insert_entry ( self , value : V ) -> RustcOccupiedEntry < ' a , K , V , A > {
587
599
let bucket = self . table . insert_no_grow ( self . hash , ( self . key , value) ) ;
588
600
RustcOccupiedEntry {
589
601
key : None ,
0 commit comments