diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index 921222436..5598f5edc 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -285,15 +285,18 @@ impl<'b, T: Clone + Copy + 'static> Bucket { }; elem.set_ref_count(&mut self.index, ref_count); - let bucket_ix = elem.data_bucket_ix(&self.index); + let current_multiple_slots = elem.get_multiple_slots(&self.index); + let bucket_ix = + IndexEntry::::data_bucket_from_num_slots(current_multiple_slots.num_slots()); let num_slots = data_len as u64; - if best_fit_bucket == bucket_ix && elem.num_slots(&self.index) > 0 { + 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); assert!(!current_bucket.is_free(elem_loc)); let slice: &mut [T] = current_bucket.get_mut_cell_slice(elem_loc, data_len as u64); - elem.set_num_slots(&mut self.index, num_slots); + let current_multiple_slots = elem.get_multiple_slots_mut(&mut self.index); + current_multiple_slots.set_num_slots(num_slots); slice.iter_mut().zip(data).for_each(|(dest, src)| { *dest = *src; @@ -318,12 +321,12 @@ impl<'b, T: Clone + Copy + 'static> Bucket { let ix = i % cap; if best_bucket.is_free(ix) { let elem_loc = elem.data_loc(&self.index, current_bucket); - let old_slots = elem.num_slots(&self.index); + 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); multiple_slots .set_storage_capacity_when_created_pow2(best_bucket.capacity_pow2); - elem.set_num_slots(&mut self.index, num_slots); + multiple_slots.set_num_slots(num_slots); if old_slots > 0 { let current_bucket = &mut self.data[bucket_ix as usize]; current_bucket.free(elem_loc); @@ -346,7 +349,8 @@ impl<'b, T: Clone + Copy + 'static> Bucket { pub fn delete_key(&mut self, key: &Pubkey) { if let Some((elem, elem_ix)) = self.find_index_entry(key) { - if elem.num_slots(&self.index) > 0 { + let multiple_slots = elem.get_multiple_slots_mut(&mut self.index); + if multiple_slots.num_slots() > 0 { let ix = elem.data_bucket_ix(&self.index) as usize; let data_bucket = &self.data[ix]; let loc = elem.data_loc(&self.index, data_bucket); diff --git a/bucket_map/src/index_entry.rs b/bucket_map/src/index_entry.rs index 2fe844450..072c67ec1 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -107,6 +107,14 @@ impl MultipleSlots { fn storage_offset(&self) -> u64 { self.storage_cap_and_offset.offset() } + + pub(crate) fn num_slots(&self) -> Slot { + self.num_slots + } + + pub(crate) fn set_num_slots(&mut self, num_slots: Slot) { + self.num_slots = num_slots; + } } /// Pack the storage offset and capacity-when-crated-pow2 fields into a single u64 @@ -143,10 +151,12 @@ impl IndexEntryPlaceInBucket { } pub fn data_bucket_ix(&self, index_bucket: &BucketStorage>) -> u64 { - IndexEntry::::data_bucket_from_num_slots(self.num_slots(index_bucket)) + IndexEntry::::data_bucket_from_num_slots( + self.get_multiple_slots(index_bucket).num_slots(), + ) } - fn get_multiple_slots<'a>( + pub(crate) fn get_multiple_slots<'a>( &self, index_bucket: &'a BucketStorage>, ) -> &'a MultipleSlots { @@ -184,7 +194,8 @@ impl IndexEntryPlaceInBucket { index_bucket: &BucketStorage>, data_buckets: &'a [BucketStorage], ) -> Option<(&'a [T], RefCount)> { - let num_slots = self.num_slots(index_bucket); + let multiple_slots = self.get_multiple_slots(index_bucket); + let num_slots = multiple_slots.num_slots(); let slice = if num_slots > 0 { let data_bucket_ix = self.data_bucket_ix(index_bucket); let data_bucket = &data_buckets[data_bucket_ix as usize]; @@ -218,14 +229,6 @@ impl IndexEntryPlaceInBucket { let index_entry = index_bucket.get_mut::>(self.ix); index_entry.ref_count = ref_count; } - - pub fn num_slots(&self, index_bucket: &BucketStorage>) -> Slot { - self.get_multiple_slots(index_bucket).num_slots - } - - pub fn set_num_slots(&self, index_bucket: &mut BucketStorage>, num_slots: Slot) { - self.get_multiple_slots_mut(index_bucket).num_slots = num_slots; - } } #[cfg(test)]