From 4c41b171ee9160e325a58e6af714b254172dfca7 Mon Sep 17 00:00:00 2001 From: brooks Date: Wed, 29 Mar 2023 19:04:00 -0400 Subject: [PATCH] move fns around --- bucket_map/src/bucket_storage.rs | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index a898ca49b66bfe..3b2a6a61938528 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -169,19 +169,23 @@ impl BucketStorage { self.count.fetch_sub(1, Ordering::Relaxed); } - pub fn get(&self, ix: u64) -> &T { - &self.get_cell_slice::(ix, 1)[0] - } - - pub(crate) fn get_start_offset_with_header(&self, ix: u64) -> usize { + fn get_start_offset_with_header(&self, ix: u64) -> usize { assert!(ix < self.capacity(), "bad index size"); (self.cell_size * ix) as usize } - pub(crate) fn get_start_offset_no_header(&self, ix: u64) -> usize { + fn get_start_offset_no_header(&self, ix: u64) -> usize { self.get_start_offset_with_header(ix) + O::offset_to_first_data() } + pub fn get(&self, ix: u64) -> &T { + &self.get_cell_slice::(ix, 1)[0] + } + + pub fn get_mut(&mut self, ix: u64) -> &mut T { + &mut self.get_mut_cell_slice::(ix, 1)[0] + } + pub fn get_cell_slice(&self, ix: u64, len: u64) -> &[T] { let start = self.get_start_offset_no_header(ix); let len = std::mem::size_of::() * len as usize; @@ -198,16 +202,6 @@ impl BucketStorage { unsafe { std::slice::from_raw_parts(ptr, len) } } - pub(crate) fn get_mut_from_parts(item_slice: &mut [u8]) -> &mut T { - assert!(std::mem::size_of::() <= item_slice.len()); - let item = item_slice.as_mut_ptr() as *mut T; - unsafe { &mut *item } - } - - pub fn get_mut(&mut self, ix: u64) -> &mut T { - &mut self.get_mut_cell_slice::(ix, 1)[0] - } - pub fn get_mut_cell_slice(&mut self, ix: u64, len: u64) -> &mut [T] { let start = self.get_start_offset_no_header(ix); let len = std::mem::size_of::() * len as usize; @@ -224,6 +218,18 @@ impl BucketStorage { unsafe { std::slice::from_raw_parts_mut(ptr, len) } } + pub(crate) fn get_from_parts(item_slice: &[u8]) -> &T { + assert!(std::mem::size_of::() <= item_slice.len()); + let item = item_slice.as_ptr() as *const T; + unsafe { &*item } + } + + pub(crate) fn get_mut_from_parts(item_slice: &mut [u8]) -> &mut T { + assert!(std::mem::size_of::() <= item_slice.len()); + let item = item_slice.as_mut_ptr() as *mut T; + unsafe { &mut *item } + } + fn new_map( drives: &[PathBuf], cell_size: usize,