diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index e4ec015c1..943c79483 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -76,7 +76,7 @@ pub struct Bucket { pub reallocated: Reallocated, } -impl<'b, T: Clone + Copy + 'b> Bucket { +impl<'b, T: Clone + Copy + 'static> Bucket { pub fn new( drives: Arc>, max_search: MaxSearch, diff --git a/bucket_map/src/bucket_api.rs b/bucket_map/src/bucket_api.rs index 4f33f6e71..695d6836b 100644 --- a/bucket_map/src/bucket_api.rs +++ b/bucket_map/src/bucket_api.rs @@ -16,7 +16,7 @@ use { type LockedBucket = RwLock>>; -pub struct BucketApi { +pub struct BucketApi { drives: Arc>, max_search: MaxSearch, pub stats: Arc, diff --git a/bucket_map/src/bucket_map.rs b/bucket_map/src/bucket_map.rs index bad5cec5a..86ceef7e8 100644 --- a/bucket_map/src/bucket_map.rs +++ b/bucket_map/src/bucket_map.rs @@ -25,7 +25,7 @@ impl BucketMapConfig { } } -pub struct BucketMap { +pub struct BucketMap { buckets: Vec>>, drives: Arc>, max_buckets_pow2: u8, diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index 69e3eecd2..b69166eb8 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -214,13 +214,8 @@ impl BucketStorage { } } - pub fn get_empty_cell_slice(&self) -> &[T] { - let len = 0; - let item_slice: &[u8] = &self.mmap[0..0]; - unsafe { - let item = item_slice.as_ptr() as *const T; - std::slice::from_raw_parts(item, len as usize) - } + pub fn get_empty_cell_slice() -> &'static [T] { + &[] } pub fn get_cell_slice(&self, ix: u64, len: u64) -> &[T] { diff --git a/bucket_map/src/index_entry.rs b/bucket_map/src/index_entry.rs index 91e77ac8c..7917488c7 100644 --- a/bucket_map/src/index_entry.rs +++ b/bucket_map/src/index_entry.rs @@ -94,18 +94,17 @@ impl IndexEntry { self.storage_offset() << (storage.capacity_pow2 - self.storage_capacity_when_created_pow2()) } - pub fn read_value<'a, T>(&self, bucket: &'a Bucket) -> Option<(&'a [T], RefCount)> { - let data_bucket_ix = self.data_bucket_ix(); - let data_bucket = &bucket.data[data_bucket_ix as usize]; + pub fn read_value<'a, T: 'static>(&self, bucket: &'a Bucket) -> Option<(&'a [T], RefCount)> { let slice = if self.num_slots > 0 { + let data_bucket_ix = self.data_bucket_ix(); + let data_bucket = &bucket.data[data_bucket_ix as usize]; let loc = self.data_loc(data_bucket); let uid = Self::key_uid(&self.key); - assert_eq!(Some(uid), bucket.data[data_bucket_ix as usize].uid(loc)); - bucket.data[data_bucket_ix as usize].get_cell_slice(loc, self.num_slots) + assert_eq!(Some(uid), data_bucket.uid(loc)); + data_bucket.get_cell_slice(loc, self.num_slots) } else { // num_slots is 0. This means we don't have an actual allocation. - // can we trust that the data_bucket is even safe? - bucket.data[data_bucket_ix as usize].get_empty_cell_slice() + BucketStorage::get_empty_cell_slice() }; Some((slice, self.ref_count)) }