1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::fmt;
use std::time::Duration;

// pub(crate) const MAX_ALLOC_SIZE: usize = 0xFFFFFFF;
pub(crate) const MAX_MAP_SIZE: u64 = 0x0FFF_FFFF;

/// Are unaligned load/stores broken on this arch?
// pub(crate) const BROKEN_UNALIGNED: bool = false;

pub(crate) const MIN_KEYS_PER_PAGE: usize = 2;

#[allow(clippy::upper_case_acronyms)]
pub(crate) type PGID = u64;

#[allow(clippy::upper_case_acronyms)]
pub(crate) type TXID = u64;

pub(crate) const MAX_MMAP_STEP: u64 = 1 << 30;

/// database mime header
pub(crate) const MAGIC: u32 = 0xED0C_DAED;

/// database version
pub(crate) const VERSION: u32 = 2;

// TODO: openbsd
pub(crate) const IGNORE_NOSYNC: bool = true;

pub(crate) const DEFAULT_MAX_BATCH_SIZE: usize = 1000;

pub(crate) const DEFAULT_MAX_BATCH_DELAY: Duration = Duration::from_millis(10000);
// pub(crate) const DEFAULT_ALLOC_SIZE: u64 = 16 * 1024 * 1024;

bitflags! {
    /// Defines type of the page
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Flags: u16 {
        /// Either branch or bucket page
        const BRANCHES = 0b00001;
        /// Leaf page
        const LEAVES = 0b00010;
        /// Meta page
        const META = 0b00100;
        /// Freelist page
        const FREELIST = 0b10000;
    }
}

impl fmt::Display for Flags {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let d = match *self {
            Flags::BRANCHES => "branches".to_string(),
            Flags::LEAVES => "leaves".to_string(),
            Flags::META => "meta".to_string(),
            Flags::FREELIST => "freelist".to_string(),
            _ => panic!("unknown flag"),
        };
        write!(f, "{}", d)
    }
}