add Slabable trait
This commit is contained in:
parent
abc634d052
commit
d740821ab6
@ -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<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy>
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> Slabable for Queue<T> {
|
||||
fn slabs(slabs: &mut HashSet<u32>) {
|
||||
slabs.insert(size_of::<Queue<T>>() as u32);
|
||||
slabs.insert(size_of::<QueueElement<T>>() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> Queue<T> {
|
||||
pub fn new<R>(transaction: &mut TransactionHandle<R>) -> FilePointer<Queue<T>> {
|
||||
let (queue, data) = transaction.allocate();
|
||||
|
@ -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<u32>) {
|
||||
slabs.insert(size_of::<Str>() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
impl Str {
|
||||
pub fn new() -> Self {
|
||||
Self(Vector::new())
|
||||
|
@ -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<u32>) {
|
||||
slabs.insert(size_of::<Vector>() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
impl Vector {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -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<u32>);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user