pub struct BPlusTreeMap<K: Key, V, A: Argument<K> = ()> { /* private fields */ }
Expand description
A B+ tree map implemented with BPlusTree
Implementations§
Source§impl<K: Key, V, A: Argument<K>> BPlusTreeMap<K, V, A>
impl<K: Key, V, A: Argument<K>> BPlusTreeMap<K, V, A>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new BPlusTreeMap
§Examples
use sweep_bptree::BPlusTreeMap;
let map = BPlusTreeMap::<i32, i32>::new();
assert!(map.is_empty());
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no item
§Examples
use sweep_bptree::BPlusTreeMap;
let map = BPlusTreeMap::<i32, i32>::new();
assert!(map.is_empty());
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a key-value pair into the map
§Examples
use sweep_bptree::BPlusTreeMap;
let mut map = BPlusTreeMap::<i32, i32>::new();
map.insert(1, 2);
map.insert(2, 4);
assert!(!map.is_empty());
assert_eq!(map.len(), 2);
Sourcepub fn get<Q: ?Sized + Ord>(&self, key: &Q) -> Option<&V>where
K: Borrow<Q>,
pub fn get<Q: ?Sized + Ord>(&self, key: &Q) -> Option<&V>where
K: Borrow<Q>,
Returns a reference to the value corresponding to the key.
§Examples
use sweep_bptree::BPlusTreeMap;
let mut map = BPlusTreeMap::<i32, i32>::new();
map.insert(1, 2);
assert_eq!(map.get(&1).unwrap(), &2);
assert!(map.get(&2).is_none());
Sourcepub fn get_mut<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<&mut V>where
K: Borrow<Q>,
pub fn get_mut<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<&mut V>where
K: Borrow<Q>,
Returns a mut reference to the value corresponding to the key.
§Examples
use sweep_bptree::BPlusTreeMap;
let mut map = BPlusTreeMap::<i32, i32>::new();
map.insert(1, 2);
*map.get_mut(&1).unwrap() += 1;
assert_eq!(map.get(&1).unwrap(), &3);
Sourcepub fn remove<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<V>where
K: Borrow<Q>,
pub fn remove<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<V>where
K: Borrow<Q>,
Removes a key from the map, returning the value at the key if the key was previously in the map.
§Examples
use sweep_bptree::BPlusTreeMap;
let mut map = BPlusTreeMap::<i32, i32>::new();
map.insert(1, 2);
assert!(map.remove(&1).is_some());
assert!(map.remove(&2).is_none());
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Returns an iterator over the map.
§Examples
use sweep_bptree::BPlusTreeMap;
let mut map = BPlusTreeMap::<i32, i32>::new();
map.insert(1, 2);
map.insert(2, 3);
let kvs = map.iter().map(|(k, v)| (*k, *v)).collect::<Vec<_>>();
assert_eq!(kvs.len(), 2);
assert_eq!(kvs, vec![(1, 2), (2, 3)]);
Sourcepub fn root_argument(&self) -> &A
pub fn root_argument(&self) -> &A
Get root argument for the map
Sourcepub fn get_by_argument<Q>(&self, query: Q) -> Option<(&K, &V)>where
A: SearchArgument<K, Query = Q>,
pub fn get_by_argument<Q>(&self, query: Q) -> Option<(&K, &V)>where
A: SearchArgument<K, Query = Q>,
Get value by argument’s query
§Example
use sweep_bptree::BPlusTreeMap;
use sweep_bptree::argument::count::Count;
let mut map = BPlusTreeMap::<i32, i32, Count>::new();
map.insert(1, 2);
map.insert(2, 3);
map.insert(3, 4);
assert_eq!(map.get_by_argument(0), Some((&1, &2)));
assert_eq!(map.get_by_argument(1), Some((&2, &3)));
assert_eq!(map.get_by_argument(2), Some((&3, &4)));
Sourcepub fn get_mut_by_argument<Q>(&mut self, query: Q) -> Option<&mut V>where
A: SearchArgument<K, Query = Q>,
pub fn get_mut_by_argument<Q>(&mut self, query: Q) -> Option<&mut V>where
A: SearchArgument<K, Query = Q>,
Get mut referece to value by argument’s query
§Example
use sweep_bptree::BPlusTreeMap;
use sweep_bptree::argument::count::Count;
let mut map = BPlusTreeMap::<i32, i32, Count>::new();
map.insert(1, 2);
map.insert(2, 3);
map.insert(3, 4);
*map.get_mut_by_argument(0).unwrap() = 20;
assert_eq!(map.get_by_argument(0), Some((&1, &20)));
Sourcepub fn remove_by_argument<Q>(&mut self, query: Q) -> Option<(K, V)>where
A: SearchArgument<K, Query = Q>,
pub fn remove_by_argument<Q>(&mut self, query: Q) -> Option<(K, V)>where
A: SearchArgument<K, Query = Q>,
Remove by argument’s query, returns deleted Key Value if exist
§Example
use sweep_bptree::BPlusTreeMap;
use sweep_bptree::argument::count::Count;
let mut map = BPlusTreeMap::<i32, i32, Count>::new();
map.insert(1, 2);
map.insert(2, 3);
map.insert(3, 4);
assert_eq!(map.remove_by_argument(0), Some((1, 2)));
assert_eq!(map.remove_by_argument(0), Some((2, 3)));
assert_eq!(map.remove_by_argument(0), Some((3, 4)));
Sourcepub fn rank_by_argument<R>(&self, k: &K) -> Result<R, R>where
A: RankArgument<K, Rank = R>,
pub fn rank_by_argument<R>(&self, k: &K) -> Result<R, R>where
A: RankArgument<K, Rank = R>,
Get the rank for key
§Example
use sweep_bptree::BPlusTreeMap;
use sweep_bptree::argument::count::Count;
let mut map = BPlusTreeMap::<i32, i32, Count>::new();
map.insert(1, 2);
map.insert(2, 3);
map.insert(3, 4);
// 0 does not exists
assert_eq!(map.rank_by_argument(&0), Err(0));
// 1's rank is 0
assert_eq!(map.rank_by_argument(&1), Ok(0));
assert_eq!(map.rank_by_argument(&2), Ok(1));
assert_eq!(map.rank_by_argument(&3), Ok(2));
// 4 does not exists
assert_eq!(map.rank_by_argument(&4), Err(3));
Sourcepub fn descend_visit<VI, R>(&self, v: VI) -> Option<R>where
VI: DescendVisit<K, V, A, Result = R>,
pub fn descend_visit<VI, R>(&self, v: VI) -> Option<R>where
VI: DescendVisit<K, V, A, Result = R>,
Visit the tree’s node with a visitor Returns None if visitor cancelled Otherwise, returns visitor’s result
Trait Implementations§
Source§impl<K: Key, V> Default for BPlusTreeMap<K, V>
impl<K: Key, V> Default for BPlusTreeMap<K, V>
Source§impl<K: Key, V, A: Argument<K>> FromIterator<(K, V)> for BPlusTreeMap<K, V, A>
impl<K: Key, V, A: Argument<K>> FromIterator<(K, V)> for BPlusTreeMap<K, V, A>
Source§fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
Create a BPlusTreeMap from an iterator
§Example
use sweep_bptree::BPlusTreeMap;
let mut items = (0..1000).map(|i| (i, i));
let map = BPlusTreeMap::<i32, i32>::from_iter(items);
assert_eq!(map.len(), 1000);
assert_eq!(map.get(&1), Some(&1));
Auto Trait Implementations§
impl<K, V, A = ()> !Freeze for BPlusTreeMap<K, V, A>
impl<K, V, A> RefUnwindSafe for BPlusTreeMap<K, V, A>
impl<K, V, A> Send for BPlusTreeMap<K, V, A>
impl<K, V, A> Sync for BPlusTreeMap<K, V, A>
impl<K, V, A> Unpin for BPlusTreeMap<K, V, A>where
A: Unpin,
impl<K, V, A> UnwindSafe for BPlusTreeMap<K, V, A>
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