mod node;
mod node_children;
mod node_text;
mod text_info;
pub(crate) use self::node::Node;
pub(crate) use self::node_children::NodeChildren;
pub(crate) use self::node_text::NodeText;
pub(crate) use self::text_info::TextInfo;
pub(crate) type Count = u64;
#[cfg(not(any(test, feature = "small_chunks")))]
mod constants {
use super::{Node, TextInfo};
use smallvec::SmallVec;
use std::{
mem::{align_of, size_of},
sync::Arc,
};
const fn cmax(a: usize, b: usize) -> usize {
if a > b {
a
} else {
b
}
}
const TARGET_TOTAL_SIZE: usize = 1024;
const ARC_COUNTERS_SIZE: usize = size_of::<std::sync::atomic::AtomicUsize>() * 2;
const NODE_CHILDREN_ALIGN: usize = cmax(align_of::<Arc<u8>>(), align_of::<TextInfo>());
const NODE_TEXT_ALIGN: usize = align_of::<SmallVec<[u8; 16]>>();
const START_OFFSET: usize = {
const NODE_INNER_ALIGN: usize = cmax(NODE_CHILDREN_ALIGN, NODE_TEXT_ALIGN);
ARC_COUNTERS_SIZE + NODE_INNER_ALIGN
};
pub(crate) const MAX_CHILDREN: usize = {
let node_list_align = align_of::<Arc<u8>>();
let info_list_align = align_of::<TextInfo>();
let field_gap = if node_list_align >= info_list_align {
0
} else {
info_list_align - node_list_align
};
let target_size = TARGET_TOTAL_SIZE - START_OFFSET - NODE_CHILDREN_ALIGN - field_gap;
target_size / (size_of::<Arc<u8>>() + size_of::<TextInfo>())
};
pub(crate) const MAX_BYTES: usize = {
let smallvec_overhead = size_of::<SmallVec<[u8; 16]>>() - 16;
TARGET_TOTAL_SIZE - START_OFFSET - smallvec_overhead
};
pub(crate) const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
pub(crate) const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
const _: () = {
assert!(
(ARC_COUNTERS_SIZE + size_of::<Node>()) == TARGET_TOTAL_SIZE,
"`Node` is not the target size in memory.",
);
};
}
#[cfg(any(test, feature = "small_chunks"))]
mod test_constants {
pub(crate) const MAX_CHILDREN: usize = 5;
pub(crate) const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
pub(crate) const MAX_BYTES: usize = 9; pub(crate) const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
}
#[cfg(not(any(test, feature = "small_chunks")))]
pub(crate) use self::constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
#[cfg(any(test, feature = "small_chunks"))]
pub(crate) use self::test_constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};