#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum SegmentPageKind {
Data = 0x10,
Index = 0x11,
Overflow = 0x12,
}
impl SegmentPageKind {
#[must_use]
pub fn as_page_kind(self) -> crate::pager::format::page_kind::PageKind {
match self {
Self::Data => crate::pager::format::page_kind::PageKind::SegmentData,
Self::Index => crate::pager::format::page_kind::PageKind::SegmentIndex,
Self::Overflow => crate::pager::format::page_kind::PageKind::SegmentOverflow,
}
}
}
pub type PageId = u64;
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub struct ExtentRef {
pub start_page_id: u64,
pub count: u32,
}
impl ExtentRef {
#[must_use]
pub const fn new(start_page_id: u64, count: u32) -> Self {
Self {
start_page_id,
count,
}
}
}
#[cfg(not(target_arch = "wasm32"))]
pub use super::mmap::MmapView;
#[cfg(target_arch = "wasm32")]
#[derive(Debug)]
pub struct MmapView {
_private: (),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExtentIndexEntry {
pub start_page_id: u64,
pub page_count: u32,
pub logical_bytes: u64,
}
pub const EXTENT_INDEX_ENTRY_LEN: usize = 32;
impl ExtentIndexEntry {
#[must_use]
pub fn encode(self) -> [u8; EXTENT_INDEX_ENTRY_LEN] {
let mut buf = [0u8; EXTENT_INDEX_ENTRY_LEN];
buf[0..8].copy_from_slice(&self.start_page_id.to_le_bytes());
buf[8..12].copy_from_slice(&self.page_count.to_le_bytes());
buf[16..24].copy_from_slice(&self.logical_bytes.to_le_bytes());
buf
}
#[must_use]
pub fn decode(buf: &[u8; EXTENT_INDEX_ENTRY_LEN]) -> Self {
let mut b8 = [0u8; 8];
b8.copy_from_slice(&buf[0..8]);
let start_page_id = u64::from_le_bytes(b8);
let mut b4 = [0u8; 4];
b4.copy_from_slice(&buf[8..12]);
let page_count = u32::from_le_bytes(b4);
b8.copy_from_slice(&buf[16..24]);
let logical_bytes = u64::from_le_bytes(b8);
Self {
start_page_id,
page_count,
logical_bytes,
}
}
}
#[non_exhaustive]
#[derive(Debug, Default, Clone, Copy)]
pub struct GcStats {
pub reclaimed_segments: u64,
pub reclaimed_bytes: u64,
}