mace-kv 0.0.32

A fast, cross-platform embedded key-value storage engine with ACID, MVCC, and flash-optimized storage
Documentation
use crate::types::{
    header::BoxHeader,
    refbox::{BoxRef, BoxView},
};
use crate::utils::OpCode;
use crate::utils::data::Position;

pub trait ILoader {
    fn copy_without_pin(&self) -> Self;

    fn copy_with_pin(&self) -> Self;

    fn pin(&self, data: BoxRef);

    fn load(&self, addr: u64) -> Result<BoxView, OpCode>;

    fn load_remote(&self, addr: u64) -> Result<BoxRef, OpCode>;

    fn load_remote_uncached(&self, _addr: u64) -> BoxRef {
        unimplemented!()
    }

    fn load_unchecked(&self, addr: u64) -> BoxView {
        self.load(addr).expect("must exist")
    }

    fn load_remote_unchecked(&self, addr: u64) -> BoxRef {
        self.load_remote(addr).expect("must exist")
    }
}

pub trait IAsBoxRef {
    fn as_box(&self) -> BoxRef;
}

pub trait IBoxHeader {
    fn box_header(&self) -> &BoxHeader;

    fn box_header_mut(&mut self) -> &mut BoxHeader;
}

pub trait IHeader<T> {
    fn header(&self) -> &T;

    fn header_mut(&mut self) -> &mut T;
}

pub trait IFrameAlloc {
    fn alloc(&mut self, size: u32) -> BoxRef;

    fn inline_size(&self) -> usize;

    fn checkpoint_lsn(&self, _group: u8) -> Position {
        Position::MIN
    }
}

pub trait IKey: Default + IKeyCodec + Ord {
    fn raw(&self) -> &[u8];

    fn txid(&self) -> u64;

    fn to_string(&self) -> String;
}

pub trait IDecode {
    fn decode_from(raw: &[u8]) -> Self;
}

pub trait ICodec: IDecode + Copy {
    fn packed_size(&self) -> usize;

    fn encode_to(&self, to: &mut [u8]);
}

pub trait IKeyCodec: ICodec {
    fn remove_prefix(&self, prefix_len: usize) -> Self;
}

pub trait IVal: ICodec + Clone {
    fn is_tombstone(&self) -> bool;

    fn group_id(&self) -> u8 {
        unimplemented!()
    }
}

pub trait IAsSlice: Sized {
    fn as_slice(&self) -> &[u8] {
        let p = self as *const Self;
        unsafe { std::slice::from_raw_parts(p.cast(), size_of::<Self>()) }
    }

    fn from_slice(x: &[u8]) -> Self {
        assert!(x.len() >= size_of::<Self>());
        unsafe { std::ptr::read_unaligned(x.as_ptr().cast::<Self>()) }
    }

    fn len(&self) -> usize {
        size_of::<Self>()
    }
}