pub mod serialize;
pub mod read;
pub mod buffer;
use std::borrow::Cow;
use bytemuck::{Pod, Zeroable};
pub mod verify;
pub use verify::*;
pub mod merge;
pub use merge::*;
use crate::{buffer::Buffer, read::ReadAt};
pub mod filter;
pub use filter::*;
pub mod file_kind;
pub use file_kind::*;
pub trait Query<'a> {
type QueryType;
type Key: ReadAt<'a>;
fn query(&self, query: Self::QueryType) -> BitMask;
fn query_by_key(&self, val: <Self::Key as ReadAt<'a>>::ReadOutput) -> Option<usize>;
fn query_by_keys(&self, vals: &[<Self::Key as ReadAt<'a>>::ReadOutput],) -> BitMask;
}
pub trait QueryType {
fn new()-> Self;
}
#[repr(u8)]
pub enum DataType { Inline, Offset, Union }
impl DataType {
#[inline(always)]
pub fn is_inline_flag(&self) -> bool {
matches!(self,DataType::Inline)
}
#[inline(always)]
pub fn is_offset_flag(&self) -> bool {
match self {
DataType::Offset | DataType::Union => true,
_ => false
}
}
#[inline(always)]
pub fn is_union_flag(&self) -> bool {
matches!(self,DataType::Union)
}
}
pub trait Table: Default {
type VTableTemplate;
const VTABLE_TEMPLATE: Self::VTableTemplate;
type View<'a>;
fn view<'a>(buf: &'a[u8], table_idx: usize) -> Self::View<'a>;
fn as_buffer(&self) -> impl Buffer;
}
pub trait Flat: Pod + Zeroable{
fn to_le_bytes(&self) -> Cow<'_, [u8]>;
fn from_le_bytes(bytes:&[u8]) -> Self;
}
pub trait Row: Table {
type Registry;
fn write_as_registry<B: Buffer>(&self, buf: &mut B) -> usize;
}
pub trait RegistryView<'a> {
type RowRef;
fn get_row(&self, i: usize) -> Self::RowRef;
fn len(&self) -> usize;
#[inline(always)]
fn is_empty(&self) -> bool{
self.len() == 0
}
}
#[inline(always)]
pub const fn bitmax(a: usize, b: usize) -> usize {
let condition = (a < b) as usize;
let mask = 0usize.wrapping_sub(condition);
a ^ ((a ^ b) & mask)
}