#![deny(missing_docs)]
#![no_std]
#[cfg(target_pointer_width = "16")]
compile_error!("`target_pointer_width` must be larger than or equal to 32");
#[cfg(not(feature = "alloc"))]
compile_error!("`alloc` feature is currently required to build this crate");
#[macro_use]
extern crate alloc;
mod builder;
pub mod errors;
mod mapper;
pub mod mptrie;
pub mod trie;
mod utils;
pub(crate) const OFFSET_MASK: u32 = 0x7fff_ffff;
pub(crate) const INVALID_IDX: u32 = 0xffff_ffff;
pub(crate) const MAX_VALUE: u32 = OFFSET_MASK;
pub(crate) const END_CODE: u32 = 0;
pub const END_MARKER: char = '\u{ffff}';
pub use mptrie::MpTrie;
pub use trie::Trie;
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
struct Node {
base: u32,
check: u32,
}
impl Node {
#[inline(always)]
pub const fn get_base(&self) -> u32 {
self.base & OFFSET_MASK
}
#[inline(always)]
pub const fn get_check(&self) -> u32 {
self.check & OFFSET_MASK
}
#[inline(always)]
pub const fn is_leaf(&self) -> bool {
self.base & !OFFSET_MASK != 0
}
#[inline(always)]
pub const fn has_leaf(&self) -> bool {
self.check & !OFFSET_MASK != 0
}
#[inline(always)]
pub const fn is_vacant(&self) -> bool {
self.base == OFFSET_MASK && self.check == OFFSET_MASK
}
pub const fn io_bytes() -> usize {
8
}
#[inline(always)]
fn serialize(&self) -> [u8; 8] {
let mut bytes = [0; 8];
bytes[0..4].copy_from_slice(&self.base.to_le_bytes());
bytes[4..8].copy_from_slice(&self.check.to_le_bytes());
bytes
}
#[inline(always)]
fn deserialize(bytes: [u8; 8]) -> Self {
Self {
base: u32::from_le_bytes(bytes[0..4].try_into().unwrap()),
check: u32::from_le_bytes(bytes[4..8].try_into().unwrap()),
}
}
}