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
//! # Transient Index using B-Trees
//!
//! `transient-btree-index` allows you to create a BTree index backed by temporary files.
//! This is helpful if you
//!
//! - need to index large datasets (thus only working on disk) by inserting entries in unsorted order,
//! - want to query entries (get and range queries) while the index is still constructed, e.g. to check existence of a previous entry, and
//! - need support for all serde-serializable key and value types with varying key-size.
//!
//! Because of its intended use case, it is therefore **not possible to**
//!
//! - delete entries once they are inserted (you can use [`Option`] values and set them to [`Option::None`], but this will not reclaim any used space),
//! - persist the index to a file (you can use other crates like [sstable](https://crates.io/crates/sstable) to create immutable maps), or
//! - load an existing index file (you might want to use an immutable map file and this index can act as an "overlay" for all changed entries).
//!
//! # Example
//!
//! ```rust
//! use transient_btree_index::{BtreeConfig, BtreeIndex, Error};
//!
//! fn main() -> std::result::Result<(), Error> {
//! let mut b = BtreeIndex::<u16,u16>::with_capacity(BtreeConfig::default(), 10)?;
//! b.insert(1,2)?;
//! b.insert(200, 4)?;
//! b.insert(20, 3)?;
//!
//! assert_eq!(true, b.contains_key(&200)?);
//! assert_eq!(false, b.contains_key(&2)?);
//!
//! assert_eq!(3, b.get(&20)?.unwrap());
//!
//! for e in b.range(1..30)? {
//! let (k, v) = e?;
//! dbg!(k, v);
//! }
//! Ok(())
//! }
//! ```
pub use ;
pub use Error;
use MmapMut;
const KB: usize = 1 << 10;
const PAGE_SIZE: usize = 4 * KB;
/// Create a new memory mapped file with the capacity in bytes.