From ef81b5ab5f4eaad26c5da48155db9e703477886f Mon Sep 17 00:00:00 2001 From: jeff washington Date: Thu, 30 Mar 2023 12:24:41 -0500 Subject: [PATCH] disk index: move fn `data_loc` to `MultipleSlots` --- bucket_map/src/bucket.rs | 6 +++--- bucket_map/src/index_entry.rs | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index a26f3168fe6459..9a4c649db1d82b 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 0c0f613ab8093e..80dc68967fdfcf 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -86,12 +86,15 @@ pub(crate) struct MultipleSlots { } impl MultipleSlots { - fn set_storage_capacity_when_created_pow2(&mut self, storage_capacity_when_created_pow2: u8) { + pub(crate) fn set_storage_capacity_when_created_pow2( + &mut self, + storage_capacity_when_created_pow2: u8, + ) { self.storage_cap_and_offset .set_capacity_when_created_pow2(storage_capacity_when_created_pow2) } - fn set_storage_offset(&mut self, storage_offset: u64) { + pub(crate) fn set_storage_offset(&mut self, storage_offset: u64) { self.storage_cap_and_offset .set_offset_checked(storage_offset) .expect("New storage offset must fit into 7 bytes!") @@ -130,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 @@ -188,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>, @@ -210,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 {