1mod node;
2mod node_children;
3mod node_text;
4mod text_info;
5
6pub(crate) use self::node::Node;
7pub(crate) use self::node_children::NodeChildren;
8pub(crate) use self::node_text::NodeText;
9pub(crate) use self::text_info::TextInfo;
10
11pub(crate) type Count = u64;
13
14#[cfg(not(any(test, feature = "small_chunks")))]
16mod constants {
17 use super::{Node, TextInfo};
18 use smallvec::SmallVec;
19 use std::{
20 mem::{align_of, size_of},
21 sync::Arc,
22 };
23
24 const fn cmax(a: usize, b: usize) -> usize {
27 if a > b {
28 a
29 } else {
30 b
31 }
32 }
33
34 const TARGET_TOTAL_SIZE: usize = 1024;
38
39 const ARC_COUNTERS_SIZE: usize = size_of::<std::sync::atomic::AtomicUsize>() * 2;
41
42 const NODE_CHILDREN_ALIGN: usize = cmax(align_of::<Arc<u8>>(), align_of::<TextInfo>());
44 const NODE_TEXT_ALIGN: usize = align_of::<SmallVec<[u8; 16]>>();
45 const START_OFFSET: usize = {
46 const NODE_INNER_ALIGN: usize = cmax(NODE_CHILDREN_ALIGN, NODE_TEXT_ALIGN);
47 ARC_COUNTERS_SIZE + NODE_INNER_ALIGN
49 };
50
51 #[doc(hidden)] pub const MAX_CHILDREN: usize = {
54 let node_list_align = align_of::<Arc<u8>>();
55 let info_list_align = align_of::<TextInfo>();
56 let field_gap = if node_list_align >= info_list_align {
57 0
58 } else {
59 info_list_align - node_list_align
63 };
64
65 let target_size = TARGET_TOTAL_SIZE - START_OFFSET - NODE_CHILDREN_ALIGN - field_gap;
67
68 target_size / (size_of::<Arc<u8>>() + size_of::<TextInfo>())
69 };
70 #[doc(hidden)] pub const MAX_BYTES: usize = {
72 let smallvec_overhead = size_of::<SmallVec<[u8; 16]>>() - 16;
73 TARGET_TOTAL_SIZE - START_OFFSET - smallvec_overhead
74 };
75
76 #[doc(hidden)] pub const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
82 #[doc(hidden)] pub const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
84
85 const _: () = {
87 assert!(
88 (ARC_COUNTERS_SIZE + size_of::<Node>()) == TARGET_TOTAL_SIZE,
89 "`Node` is not the target size in memory.",
90 );
91 };
92}
93
94#[cfg(any(test, feature = "small_chunks"))]
98mod test_constants {
99 #[doc(hidden)] pub const MAX_CHILDREN: usize = 5;
101 #[doc(hidden)] pub const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
103
104 #[doc(hidden)] pub const MAX_BYTES: usize = 9; #[doc(hidden)] pub const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
109}
110
111#[cfg(not(any(test, feature = "small_chunks")))]
112pub use self::constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
113
114#[cfg(any(test, feature = "small_chunks"))]
115pub use self::test_constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};