byodb_rust/core/
consts.rs

1//! Constants related to memory page size and offsets.
2
3const AARCH64_MACOS_NON_TEST: bool =
4    cfg!(all(target_arch = "aarch64", target_os = "macos", not(test)));
5
6/// Size of a page.
7pub(crate) const PAGE_SIZE: usize = if AARCH64_MACOS_NON_TEST {
8    16384 // 16KB
9} else {
10    4096 // 4KB
11};
12
13/// The maximum allowed key size in a tree.
14pub const MAX_KEY_SIZE: usize = 1000;
15/// The maximum allowed value size in a tree.
16pub const MAX_VALUE_SIZE: usize = 1000;
17
18const _: () = {
19    assert!(PAGE_SIZE <= (1 << 16), "page size is within 16 bits");
20    assert!(
21        (PAGE_SIZE as isize)
22            - 2 // type
23            - 2 // nkeys
24            // 3 keys + overhead
25            - 3 * (8 + 2 + MAX_KEY_SIZE as isize)
26            >= 0,
27        "3 keys of max size cannot fit into an internal node page"
28    );
29    assert!(
30        (PAGE_SIZE as isize)
31            - 2 // type
32            - 2 // nkeys
33            // 2 key-value pairs + overhead
34            - 2*(2 + 2 + 2 + MAX_KEY_SIZE as isize + MAX_VALUE_SIZE as isize)
35            >= 0,
36        "2 key-value pairs of max size cannot fit into a leaf node page"
37    );
38};