Crates.io | transient-btree-index |
lib.rs | transient-btree-index |
version | 0.5.1 |
source | src |
created_at | 2022-02-10 17:25:45.825558 |
updated_at | 2023-11-14 11:25:20.589711 |
description | This crate allows you to create a BTree index backed by temporary files. |
homepage | |
repository | https://github.com/thomaskrause/transient-btree-index |
max_upload_size | |
id | 530368 |
size | 101,295 |
transient-btree-index
allows you to create a BTree index backed by temporary files.
This is helpful if you
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 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).
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(())
}