diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index a26f3168f..9a4c649db 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -293,7 +293,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { if best_fit_bucket == bucket_ix && current_multiple_slots.num_slots() > 0 { let current_bucket = &mut self.data[bucket_ix as usize]; // in place update - let elem_loc = elem.data_loc(&self.index, current_bucket); + let elem_loc = current_multiple_slots.data_loc(current_bucket); assert!(!current_bucket.is_free(elem_loc)); let slice: &mut [T] = current_bucket.get_mut_cell_slice(elem_loc, data_len as u64); let current_multiple_slots = elem.get_multiple_slots_mut(&mut self.index); @@ -321,7 +321,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { for i in pos..pos + (max_search * 10).min(cap) { let ix = i % cap; if best_bucket.is_free(ix) { - let elem_loc = elem.data_loc(&self.index, current_bucket); + let elem_loc = current_multiple_slots.data_loc(current_bucket); let old_slots = current_multiple_slots.num_slots(); let multiple_slots = elem.get_multiple_slots_mut(&mut self.index); multiple_slots.set_storage_offset(ix); @@ -354,7 +354,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { if multiple_slots.num_slots() > 0 { let ix = multiple_slots.data_bucket_ix() as usize; let data_bucket = &self.data[ix]; - let loc = elem.data_loc(&self.index, data_bucket); + let loc = multiple_slots.data_loc(data_bucket); let data_bucket = &mut self.data[ix]; //debug!( "DATA FREE {:?} {} {} {}", key, elem.data_location, data_bucket.capacity, elem_uid ); data_bucket.free(loc); diff --git a/bucket_map/src/index_entry.rs b/bucket_map/src/index_entry.rs index b0b485d0d..80dc68967 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -133,6 +133,12 @@ impl MultipleSlots { (Slot::BITS - (num_slots - 1).leading_zeros()) as u64 } } + + /// This function maps the original data location into an index in the current bucket storage. + /// This is coupled with how we resize bucket storages. + pub(crate) fn data_loc(&self, storage: &BucketStorage) -> u64 { + self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2()) + } } /// Pack the storage offset and capacity-when-crated-pow2 fields into a single u64 @@ -191,18 +197,6 @@ impl IndexEntryPlaceInBucket { index_entry.ref_count } - /// This function maps the original data location into an index in the current bucket storage. - /// This is coupled with how we resize bucket storages. - pub fn data_loc( - &self, - index_bucket: &BucketStorage>, - storage: &BucketStorage, - ) -> u64 { - let multiple_slots = self.get_multiple_slots(index_bucket); - multiple_slots.storage_offset() - << (storage.capacity_pow2 - multiple_slots.storage_capacity_when_created_pow2()) - } - pub fn read_value<'a>( &self, index_bucket: &BucketStorage>, @@ -213,7 +207,7 @@ impl IndexEntryPlaceInBucket { let slice = if num_slots > 0 { let data_bucket_ix = multiple_slots.data_bucket_ix(); let data_bucket = &data_buckets[data_bucket_ix as usize]; - let loc = self.data_loc(index_bucket, data_bucket); + let loc = multiple_slots.data_loc(data_bucket); assert!(!data_bucket.is_free(loc)); data_bucket.get_cell_slice(loc, num_slots) } else {