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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/// A lock-free log-structured b-link tree.

extern crate libc;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate bincode;
extern crate time;
extern crate rand;

// transactional kv with multi-key ops
pub use db::DB;
// atomic lock-free tree
pub use tree::{FANOUT, Tree};
// lock-free pagecache
pub use page::{Materializer, PageCache};
// lock-free log-structured storage
pub use log::{HEADER_LEN, LockFreeLog, Log, MAX_BUF_SZ, N_BUFS};
// lock-free stack
pub use stack::Stack;
// lock-free radix tree
pub use radix::Radix;

use crc16::crc16_arr;

macro_rules! rep_no_copy {
    ($e:expr; $n:expr) => {
        {
            let mut v = Vec::with_capacity($n);
            for _ in 0..$n {
                v.push($e);
            }
            v
        }
    };
}

#[cfg(test)]
fn test_fail() -> bool {
    use rand::Rng;
    rand::thread_rng().gen::<bool>();
    // TODO when the time is right, return the gen'd bool
    false
}

#[cfg(not(test))]
#[inline(always)]
fn test_fail() -> bool {
    false
}

mod db;
mod tree;
mod bound;
mod log;
mod crc16;
mod stack;
mod page;
mod radix;
// mod gc;

pub mod ops;

use bound::Bound;
use stack::{StackIter, node_from_frag_vec};
use tree::Frag;

type LogID = u64; // LogID == file position to simplify file mapping
type PageID = usize;

type Key = Vec<u8>;
type Value = Vec<u8>;

#[inline(always)]
fn raw<T>(t: T) -> *const T {
    Box::into_raw(Box::new(t)) as *const T
}