pub struct BPlusTree<S: NodeStore> { /* private fields */ }
Expand description
B plus tree implementation, with following considerations:
- Performance critical, for sweep like algo, the sweepline’s searching and updating is on hot path
- Cursor support, after one search, it should be fairly easy to move next or prev without another search
- Memory efficient, reduce mem alloc
§Example
use sweep_bptree::{BPlusTree, NodeStoreVec};
// create a node_store with `u64` as key, `(f64, f64)` as value
let mut node_store = NodeStoreVec::<u64, (f64, f64)>::new();
let mut tree = BPlusTree::new(node_store);
// insert new value
assert!(tree.insert(3, (0., 0.)).is_none());
// update by insert again
assert_eq!(tree.insert(3, (1., 1.)).unwrap(), (0., 0.));
// remove the value
assert_eq!(tree.remove(&3).unwrap(), (1.0, 1.0));
assert!(tree.is_empty());
§Example
Create multiple owned cursors
use sweep_bptree::{BPlusTree, NodeStoreVec};
let mut node_store = NodeStoreVec::<u64, (f64, f64)>::new();
let mut tree = BPlusTree::new(node_store);
for i in 0..100 {
tree.insert(i, (i as f64, i as f64));
}
let cursor_0 = tree.cursor_first().unwrap();
let cursor_1 = tree.cursor_first().unwrap();
// remove the key 0
tree.remove(&0);
// cursor's value should be empty now
assert!(cursor_0.value(&tree).is_none());
// move to next
let cursor_next = cursor_0.next(&tree).unwrap();
assert_eq!(*cursor_next.key(), 1);
assert_eq!(cursor_next.value(&tree).unwrap().0, 1.);
// insert a new value to key 0
tree.insert(0, (100., 100.));
// now cursor_1 should retrieve the new value
assert_eq!(cursor_1.value(&tree).unwrap().0, 100.);
Implementations§
Source§impl<S: NodeStore> BPlusTree<S>
impl<S: NodeStore> BPlusTree<S>
Sourcepub fn descend_visit<V>(&self, v: V) -> Option<V::Result>
pub fn descend_visit<V>(&self, v: V) -> Option<V::Result>
visit the tree descendly through visitor v
Source§impl<S> BPlusTree<S>where
S: NodeStore,
impl<S> BPlusTree<S>where
S: NodeStore,
Sourcepub fn node_store(&self) -> &S
pub fn node_store(&self) -> &S
Gets a reference to the NodeStore
that this BPlusTree
was created with.
Sourcepub fn root_argument(&self) -> &S::Argument
pub fn root_argument(&self) -> &S::Argument
Returns a reference to root argument
Sourcepub fn insert(&mut self, k: S::K, v: S::V) -> Option<S::V>
pub fn insert(&mut self, k: S::K, v: S::V) -> Option<S::V>
Insert a new key-value pair into the tree.
pub fn statistic(&self) -> &Statistic
Sourcepub fn get<Q: ?Sized + Ord>(&self, k: &Q) -> Option<&S::V>
pub fn get<Q: ?Sized + Ord>(&self, k: &Q) -> Option<&S::V>
Get reference to value identified by key.
Sourcepub fn get_mut<Q: ?Sized + Ord>(&mut self, k: &Q) -> Option<&mut S::V>
pub fn get_mut<Q: ?Sized + Ord>(&mut self, k: &Q) -> Option<&mut S::V>
Get mutable reference to value identified by key.
Sourcepub fn into_iter(self) -> IntoIter<S> ⓘ
pub fn into_iter(self) -> IntoIter<S> ⓘ
Consume the tree and create an iterator on (K, &V) pairs
Sourcepub fn cursor_first(&self) -> Option<Cursor<S::K>>
pub fn cursor_first(&self) -> Option<Cursor<S::K>>
Create an cursor from first elem
Sourcepub fn get_cursor(&self, k: &S::K) -> Option<(Cursor<S::K>, Option<&S::V>)>
pub fn get_cursor(&self, k: &S::K) -> Option<(Cursor<S::K>, Option<&S::V>)>
Create an cursor for k
Sourcepub fn get_by_argument<Q>(&self, query: Q) -> Option<(&S::K, &S::V)>
pub fn get_by_argument<Q>(&self, query: Q) -> Option<(&S::K, &S::V)>
get by argument
Sourcepub fn get_mut_by_argument<Q>(&mut self, query: Q) -> Option<&mut S::V>
pub fn get_mut_by_argument<Q>(&mut self, query: Q) -> Option<&mut S::V>
get mut reference to value by argument’s Query
Sourcepub fn rank_by_argument<R>(&self, k: &S::K) -> Result<R, R>
pub fn rank_by_argument<R>(&self, k: &S::K) -> Result<R, R>
Get rank for argument
Sourcepub fn remove_by_argument<Q>(&mut self, query: Q) -> Option<(S::K, S::V)>
pub fn remove_by_argument<Q>(&mut self, query: Q) -> Option<(S::K, S::V)>
remove by argument
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for BPlusTree<S>
impl<S> RefUnwindSafe for BPlusTree<S>
impl<S> Send for BPlusTree<S>
impl<S> Sync for BPlusTree<S>
impl<S> Unpin for BPlusTree<S>
impl<S> UnwindSafe for BPlusTree<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more