mod branch_children;
mod leaf_slice;
mod node;
mod slice_info;
pub(crate) use self::branch_children::BranchChildren;
pub(crate) use self::leaf_slice::LeafSlice;
pub(crate) use self::node::Node;
pub(crate) use self::slice_info::SliceInfo;
pub(crate) type Count = u64;
#[cfg(not(test))]
mod constants {
use super::SliceInfo;
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::<(SliceInfo, bool)>());
const fn node_align<T>() -> usize {
align_of::<SmallVec<[T; 16]>>()
}
const fn start_offset<T>() -> usize {
let node_inner_align = cmax(NODE_CHILDREN_ALIGN, node_align::<T>());
ARC_COUNTERS_SIZE + node_inner_align
}
pub const fn max_children<T>() -> usize {
let node_list_align = align_of::<Arc<u8>>();
let info_list_align = align_of::<(SliceInfo, bool)>();
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::<T>() - NODE_CHILDREN_ALIGN - field_gap;
target_size / (size_of::<Arc<u8>>() + size_of::<(SliceInfo, bool)>())
}
pub const fn max_len<T>() -> usize {
let smallvec_overhead = size_of::<SmallVec<[T; 16]>>();
(TARGET_TOTAL_SIZE - start_offset::<T>() - smallvec_overhead) / size_of::<T>()
}
pub const fn min_children<T>() -> usize {
max_children::<T>() / 2
}
pub const fn min_len<T>() -> usize {
(max_len::<T>() / 2) - (max_len::<T>() / 32)
}
}
#[cfg(test)]
mod test_constants {
pub const fn max_children<T>() -> usize {
5
}
pub const fn min_children<T>() -> usize {
max_children::<T>() / 2
}
pub const fn max_len<T>() -> usize {
9
}
pub const fn min_len<T>() -> usize {
(max_len::<T>() / 2) - (max_len::<T>() / 32)
}
}
#[cfg(not(test))]
pub use self::constants::{max_children, max_len, min_children, min_len};
#[cfg(test)]
pub use self::test_constants::{max_children, max_len, min_children, min_len};