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::marker::PhantomData;
|
||||||
|
use std::mem::size_of;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
||||||
|
|
||||||
|
use crate::mapped::Slabable;
|
||||||
use crate::ReaderTrait;
|
use crate::ReaderTrait;
|
||||||
use crate::{transaction, FilePointer, TransactionHandle, U64};
|
use crate::{transaction, FilePointer, TransactionHandle, U64};
|
||||||
|
|
||||||
@ -14,6 +17,13 @@ pub struct Queue<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy>
|
|||||||
_phantom: PhantomData<T>,
|
_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> {
|
impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> Queue<T> {
|
||||||
pub fn new<R>(transaction: &mut TransactionHandle<R>) -> FilePointer<Queue<T>> {
|
pub fn new<R>(transaction: &mut TransactionHandle<R>) -> FilePointer<Queue<T>> {
|
||||||
let (queue, data) = transaction.allocate();
|
let (queue, data) = transaction.allocate();
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
use std::{collections::HashSet, mem::size_of};
|
||||||
|
|
||||||
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait, TransactionHandle, U64,
|
mapped::Slabable, transaction, FilePointer, FileRange, RawFilePointer, ReaderTrait,
|
||||||
|
TransactionHandle, U64,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::vector::Vector;
|
use super::vector::Vector;
|
||||||
@ -10,6 +13,12 @@ use super::vector::Vector;
|
|||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Str(Vector);
|
pub struct Str(Vector);
|
||||||
|
|
||||||
|
impl Slabable for Str {
|
||||||
|
fn slabs(slabs: &mut HashSet<u32>) {
|
||||||
|
slabs.insert(size_of::<Str>() as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Str {
|
impl Str {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(Vector::new())
|
Self(Vector::new())
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
use std::{collections::HashSet, mem::size_of};
|
||||||
|
|
||||||
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
use zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned};
|
||||||
|
|
||||||
use crate::{
|
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)]
|
#[derive(Clone, Copy, FromBytes, FromZeroes, AsBytes, Unaligned)]
|
||||||
@ -10,6 +13,12 @@ pub struct Vector {
|
|||||||
data: FileRange,
|
data: FileRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Slabable for Vector {
|
||||||
|
fn slabs(slabs: &mut HashSet<u32>) {
|
||||||
|
slabs.insert(size_of::<Vector>() as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Vector {
|
impl Vector {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
mem::{align_of, size_of},
|
mem::{align_of, size_of},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
@ -33,3 +34,7 @@ where
|
|||||||
self.deref().read_raw(range)
|
self.deref().read_raw(range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Slabable {
|
||||||
|
fn slabs(slabs: &mut HashSet<u32>);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user