Crates.io | bztree |
lib.rs | bztree |
version | 0.2.0 |
source | src |
created_at | 2021-07-10 14:38:20.826297 |
updated_at | 2022-10-20 04:17:20.14905 |
description | BzTree implementation for Rust |
homepage | |
repository | https://github.com/Lagrang/bztree-rs |
max_upload_size | |
id | 421117 |
size | 201,794 |
BzTree(concurrent B-tree) implementation for Rust based on paper
BzTree: A High-Performance Latch-free Range Index for Non-Volatile Memory.
Current implementation doesn't support non-volatile memory and supposed
to be used only as in-memory(not persistent) data structure.
BzTree uses MwCAS crate to get access
to multi-word CAS.
use bztree::BzTree;
let tree = BzTree::new();
let guard = crossbeam_epoch::pin();
let key1 = "key_1".to_string();
assert!(tree.insert(key1.clone(), 1, &guard));
assert!(!tree.insert(key1.clone(), 5, &guard));
tree.upsert(key1.clone(), 10, &guard);
assert!(matches!(tree.delete(&key1, &guard), Some(&10)));
let key2 = "key_2".to_string();
tree.insert(key2.clone(), 2, &guard);
assert!(tree.compute(&key2, |(_, v)| Some(v + 1), &guard));
assert!(matches!(tree.get(&key2, &guard), Some(&3)));
assert!(tree.compute(&key2, |(_, v)| {
if *v == 3 {
None
} else {
Some(v + 1)
}
}, &guard));
assert!(matches!(tree.get(&key2, &guard), None));