Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk bucket: add trait fn copying_entry #31024

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bucket_map/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket<T> {
let new_ix = new_ix.unwrap();
let new_elem: &mut IndexEntry<T> = index.get_mut(new_ix);
*new_elem = *elem;
index.copying_entry(new_ix, &self.index, ix);
/*
let dbg_elem: IndexEntry = *new_elem;
assert_eq!(
Expand Down
25 changes: 25 additions & 0 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ pub trait BucketOccupied {
/// initialize this struct
/// `num_elements` is the number of elements allocated in the bucket
fn new(num_elements: usize) -> Self;
/// copying entry. Any in-memory (per-bucket) data structures may need to be copied for this `ix_old`.
/// no-op by default
fn copying_entry(
&mut self,
_element_new: &mut [u8],
_ix_new: usize,
_other: &Self,
_element_old: &[u8],
_ix_old: usize,
) {
}
}

pub struct BucketStorage<O: BucketOccupied> {
Expand Down Expand Up @@ -130,6 +141,18 @@ impl<O: BucketOccupied> BucketStorage<O> {
)
}

pub(crate) fn copying_entry(&mut self, ix_new: u64, other: &Self, ix_old: u64) {
let start = self.get_start_offset_with_header(ix_new);
let start_old = other.get_start_offset_with_header(ix_old);
self.contents.copying_entry(
&mut self.mmap[start..],
ix_new as usize,
&other.contents,
&other.mmap[start_old..],
ix_old as usize,
);
}

/// true if the entry at index 'ix' is free (as opposed to being occupied)
pub fn is_free(&self, ix: u64) -> bool {
let start = self.get_start_offset_with_header(ix);
Expand Down Expand Up @@ -294,6 +317,8 @@ impl<O: BucketOccupied> BucketStorage<O> {
let index_grow = 1 << increment;
(0..old_cap as usize).for_each(|i| {
if !old_bucket.is_free(i as u64) {
self.copying_entry((i * index_grow) as u64, old_bucket, i as u64);

{
// copying from old to new. If 'occupied' bit is stored outside the data, then
// occupied has to be set on the new entry in the new bucket.
Expand Down