@@ -220,6 +220,28 @@ impl<K, V, M> Bucket<K, V, M> {
220
220
}
221
221
}
222
222
223
+ impl < K , V , M > Deref for FullBucket < K , V , M > where M : Deref < Target =RawTable < K , V > > {
224
+ type Target = RawTable < K , V > ;
225
+ fn deref ( & self ) -> & RawTable < K , V > {
226
+ & self . table
227
+ }
228
+ }
229
+
230
+ impl < K , V , M > DerefMut for FullBucket < K , V , M > where M : DerefMut < Target =RawTable < K , V > > {
231
+ fn deref_mut ( & mut self ) -> & mut RawTable < K , V > {
232
+ & mut self . table
233
+ }
234
+ }
235
+
236
+
237
+ /// `Put` is implemented for types which provide access to a table and cannot be invalidated
238
+ /// by filling a bucket. A similar implementation for `Take` is possible.
239
+ pub trait Put { }
240
+ impl < K , V > Put for RawTable < K , V > { }
241
+ impl < ' t , K , V > Put for & ' t mut RawTable < K , V > { }
242
+ impl < K , V , M : Put > Put for Bucket < K , V , M > { }
243
+ impl < K , V , M : Put > Put for FullBucket < K , V , M > { }
244
+
223
245
impl < K , V , M : Deref < Target =RawTable < K , V > > > Bucket < K , V , M > {
224
246
pub fn new ( table : M , hash : SafeHash ) -> Bucket < K , V , M > {
225
247
Bucket :: at_index ( table, hash. inspect ( ) as usize )
@@ -320,7 +342,7 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> EmptyBucket<K, V, M> {
320
342
}
321
343
}
322
344
323
- impl < K , V , M : Deref < Target =RawTable < K , V > > + DerefMut > EmptyBucket < K , V , M > {
345
+ impl < K , V , M > EmptyBucket < K , V , M > where M : Deref < Target =RawTable < K , V > > + DerefMut + Put {
324
346
/// Puts given key and value pair, along with the key's hash,
325
347
/// into this bucket in the hashtable. Note how `self` is 'moved' into
326
348
/// this function, because this slot will no longer be empty when
@@ -359,6 +381,16 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> FullBucket<K, V, M> {
359
381
}
360
382
}
361
383
384
+ /// Duplicates the current position. This can be useful for operations
385
+ /// on two or more buckets.
386
+ pub fn stash ( self ) -> FullBucket < K , V , Self > {
387
+ FullBucket {
388
+ raw : self . raw ,
389
+ idx : self . idx ,
390
+ table : self ,
391
+ }
392
+ }
393
+
362
394
/// Get the distance between this bucket and the 'ideal' location
363
395
/// as determined by the key's hash stored in it.
364
396
///
@@ -389,12 +421,14 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> FullBucket<K, V, M> {
389
421
}
390
422
}
391
423
392
- impl < K , V , M : Deref < Target =RawTable < K , V > > + DerefMut > FullBucket < K , V , M > {
424
+ // We don't need a `Take` trait currently. This is why a mutable reference
425
+ // to the table is required.
426
+ impl < ' t , K , V > FullBucket < K , V , & ' t mut RawTable < K , V > > {
393
427
/// Removes this bucket's key and value from the hashtable.
394
428
///
395
429
/// This works similarly to `put`, building an `EmptyBucket` out of the
396
430
/// taken bucket.
397
- pub fn take ( mut self ) -> ( EmptyBucket < K , V , M > , K , V ) {
431
+ pub fn take ( mut self ) -> ( EmptyBucket < K , V , & ' t mut RawTable < K , V > > , K , V ) {
398
432
self . table . size -= 1 ;
399
433
400
434
unsafe {
@@ -410,7 +444,9 @@ impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> FullBucket<K, V, M> {
410
444
)
411
445
}
412
446
}
447
+ }
413
448
449
+ impl < K , V , M > FullBucket < K , V , M > where M : Deref < Target =RawTable < K , V > > + DerefMut {
414
450
pub fn replace ( & mut self , h : SafeHash , k : K , v : V ) -> ( SafeHash , K , V ) {
415
451
unsafe {
416
452
let old_hash = ptr:: replace ( self . raw . hash as * mut SafeHash , h) ;
@@ -455,16 +491,6 @@ impl<'t, K, V, M: Deref<Target=RawTable<K, V>> + DerefMut + 't> FullBucket<K, V,
455
491
}
456
492
}
457
493
458
- impl < K , V , M > BucketState < K , V , M > {
459
- // For convenience.
460
- pub fn expect_full ( self ) -> FullBucket < K , V , M > {
461
- match self {
462
- Full ( full) => full,
463
- Empty ( ..) => panic ! ( "Expected full bucket" )
464
- }
465
- }
466
- }
467
-
468
494
impl < K , V , M : Deref < Target =RawTable < K , V > > > GapThenFull < K , V , M > {
469
495
#[ inline]
470
496
pub fn full ( & self ) -> & FullBucket < K , V , M > {
0 commit comments