diff --git a/src/datastructures/queue.rs b/src/datastructures/queue.rs index 443a016..29f0e19 100644 --- a/src/datastructures/queue.rs +++ b/src/datastructures/queue.rs @@ -1,8 +1,11 @@ +use std::collections::HashSet; use std::marker::PhantomData; +use std::mem::size_of; use std::ops::Range; use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}; +use crate::mapped::Slabable; use crate::ReaderTrait; use crate::{transaction, FilePointer, TransactionHandle, U64}; @@ -14,6 +17,13 @@ pub struct Queue _phantom: PhantomData, } +impl Slabable for Queue { + fn slabs(slabs: &mut HashSet) { + slabs.insert(size_of::>() as u32); + slabs.insert(size_of::>() as u32); + } +} + impl Queue { pub fn new(transaction: &mut TransactionHandle) -> FilePointer> { let (queue, data) = transaction.allocate(); diff --git a/src/datastructures/string.rs b/src/datastructures/string.rs index f8105db..e1eb0eb 100644 --- a/src/datastructures/string.rs +++ b/src/datastructures/string.rs @@ -1,7 +1,10 @@ +use std::{collections::HashSet, mem::size_of}; + use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}; use crate::{ - transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait, TransactionHandle, U64, + mapped::Slabable, transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait, + TransactionHandle, U64, }; use super::vector::Vector; @@ -10,6 +13,12 @@ use super::vector::Vector; #[repr(transparent)] pub struct Str(Vector); +impl Slabable for Str { + fn slabs(slabs: &mut HashSet) { + slabs.insert(size_of::() as u32); + } +} + impl Str { pub fn new() -> Self { Self(Vector::new()) diff --git a/src/datastructures/vector.rs b/src/datastructures/vector.rs index 6b4fd0f..01f69e5 100644 --- a/src/datastructures/vector.rs +++ b/src/datastructures/vector.rs @@ -1,7 +1,10 @@ +use std::{collections::HashSet, mem::size_of}; + use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}; use crate::{ - transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait, TransactionHandle, U64, + mapped::Slabable, transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait, + TransactionHandle, U64, }; #[derive(Clone, Copy, FromBytes, FromZeroes, AsBytes, Unaligned)] @@ -10,6 +13,12 @@ pub struct Vector { data: FileRange, } +impl Slabable for Vector { + fn slabs(slabs: &mut HashSet) { + slabs.insert(size_of::() as u32); + } +} + impl Vector { pub fn new() -> Self { Self { diff --git a/src/mapped.rs b/src/mapped.rs index c94b919..fd65417 100644 --- a/src/mapped.rs +++ b/src/mapped.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashSet, mem::{align_of, size_of}, ops::Deref, sync::Arc, @@ -33,3 +34,7 @@ where self.deref().read_raw(range) } } + +pub trait Slabable { + fn slabs(slabs: &mut HashSet); +}