@@ -3,7 +3,7 @@ use core::{fmt, iter::FusedIterator, marker::PhantomData};
33use crate :: {
44 raw:: {
55 Allocator , Bucket , Global , InsertSlot , RawDrain , RawExtractIf , RawIntoIter , RawIter ,
6- RawIterHash , RawTable ,
6+ RawIterHash , RawTable , Tag ,
77 } ,
88 TryReserveError ,
99} ;
@@ -303,7 +303,6 @@ where
303303 ) -> Result < OccupiedEntry < ' _ , T , A > , AbsentEntry < ' _ , T , A > > {
304304 match self . raw . find ( hash, eq) {
305305 Some ( bucket) => Ok ( OccupiedEntry {
306- hash,
307306 bucket,
308307 table : self ,
309308 } ) ,
@@ -413,24 +412,19 @@ where
413412 ) -> Entry < ' _ , T , A > {
414413 match self . raw . find_or_find_insert_slot ( hash, eq, hasher) {
415414 Ok ( bucket) => Entry :: Occupied ( OccupiedEntry {
416- hash,
417415 bucket,
418416 table : self ,
419417 } ) ,
420418 Err ( insert_slot) => Entry :: Vacant ( VacantEntry {
421- hash,
419+ tag : Tag :: full ( hash) ,
422420 insert_slot,
423421 table : self ,
424422 } ) ,
425423 }
426424 }
427425
428- /// Returns an `OccupiedEntry` for a bucket index in the table with the given hash,
429- /// or `None` if the index is out of bounds or if its hash doesn't match.
430- ///
431- /// However, note that the hash is only compared for the few bits that are directly stored in
432- /// the table, and even in full this could not guarantee equality. Use [`OccupiedEntry::get`]
433- /// if you need to further validate a match.
426+ /// Returns an `OccupiedEntry` for the given bucket index in the table,
427+ /// or `None` if it is unoccupied or out of bounds.
434428 ///
435429 /// # Examples
436430 ///
@@ -447,29 +441,25 @@ where
447441 /// table.insert_unique(hasher(&2), (2, 'b'), |val| hasher(&val.0));
448442 /// table.insert_unique(hasher(&3), (3, 'c'), |val| hasher(&val.0));
449443 ///
450- /// let hash = hasher(&2);
451- /// let index = table.find_bucket_index(hash, |val| val.0 == 2).unwrap();
444+ /// let index = table.find_bucket_index(hasher(&2), |val| val.0 == 2).unwrap();
452445 ///
453- /// let bad_hash = !hash;
454- /// assert!(table.get_bucket_entry(bad_hash, index).is_none());
455- /// assert!(table.get_bucket_entry(hash, usize::MAX).is_none());
446+ /// assert!(table.get_bucket_entry(usize::MAX).is_none());
456447 ///
457- /// let occupied_entry = table.get_bucket_entry(hash, index).unwrap();
448+ /// let occupied_entry = table.get_bucket_entry(index).unwrap();
458449 /// assert_eq!(occupied_entry.get(), &(2, 'b'));
459450 /// assert_eq!(occupied_entry.remove().0, (2, 'b'));
460451 ///
461- /// assert!(table.find(hash , |val| val.0 == 2).is_none());
452+ /// assert!(table.find(hasher(&2) , |val| val.0 == 2).is_none());
462453 /// # }
463454 /// # fn main() {
464455 /// # #[cfg(feature = "nightly")]
465456 /// # test()
466457 /// # }
467458 /// ```
468459 #[ inline]
469- pub fn get_bucket_entry ( & mut self , hash : u64 , index : usize ) -> Option < OccupiedEntry < ' _ , T , A > > {
460+ pub fn get_bucket_entry ( & mut self , index : usize ) -> Option < OccupiedEntry < ' _ , T , A > > {
470461 Some ( OccupiedEntry {
471- hash,
472- bucket : self . raw . checked_bucket ( hash, index) ?,
462+ bucket : self . raw . checked_bucket ( index) ?,
473463 table : self ,
474464 } )
475465 }
@@ -573,7 +563,6 @@ where
573563 ) -> OccupiedEntry < ' _ , T , A > {
574564 let bucket = self . raw . insert ( hash, value, hasher) ;
575565 OccupiedEntry {
576- hash,
577566 bucket,
578567 table : self ,
579568 }
@@ -1771,7 +1760,6 @@ pub struct OccupiedEntry<'a, T, A = Global>
17711760where
17721761 A : Allocator ,
17731762{
1774- hash : u64 ,
17751763 bucket : Bucket < T > ,
17761764 table : & ' a mut HashTable < T , A > ,
17771765}
@@ -1840,12 +1828,12 @@ where
18401828 /// ```
18411829 #[ cfg_attr( feature = "inline-more" , inline) ]
18421830 pub fn remove ( self ) -> ( T , VacantEntry < ' a , T , A > ) {
1843- let ( val, slot ) = unsafe { self . table . raw . remove ( self . bucket ) } ;
1831+ let ( val, insert_slot , tag ) = unsafe { self . table . raw . remove_tagged ( self . bucket ) } ;
18441832 (
18451833 val,
18461834 VacantEntry {
1847- hash : self . hash ,
1848- insert_slot : slot ,
1835+ tag ,
1836+ insert_slot,
18491837 table : self . table ,
18501838 } ,
18511839 )
@@ -2083,7 +2071,7 @@ pub struct VacantEntry<'a, T, A = Global>
20832071where
20842072 A : Allocator ,
20852073{
2086- hash : u64 ,
2074+ tag : Tag ,
20872075 insert_slot : InsertSlot ,
20882076 table : & ' a mut HashTable < T , A > ,
20892077}
@@ -2134,10 +2122,9 @@ where
21342122 let bucket = unsafe {
21352123 self . table
21362124 . raw
2137- . insert_in_slot ( self . hash , self . insert_slot , value)
2125+ . insert_tagged_in_slot ( self . tag , self . insert_slot , value)
21382126 } ;
21392127 OccupiedEntry {
2140- hash : self . hash ,
21412128 bucket,
21422129 table : self . table ,
21432130 }
0 commit comments