disk index: move fn data_loc to MultipleSlots (#30993)

disk index: move fn `data_loc` to `MultipleSlots`
This commit is contained in:
Jeff Washington (jwash) 2023-03-30 18:23:57 -05:00 committed by GitHub
parent 399b7ba722
commit 32780353c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 16 deletions

View File

@ -293,7 +293,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
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<T> {
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<T> {
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);

View File

@ -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<DataBucket>) -> 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<T> IndexEntryPlaceInBucket<T> {
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<IndexBucket<T>>,
storage: &BucketStorage<DataBucket>,
) -> 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<IndexBucket<T>>,
@ -213,7 +207,7 @@ impl<T> IndexEntryPlaceInBucket<T> {
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 {