pub struct BPlusTreeSet<K: Key> { /* private fields */ }
Expand description
A B+ tree based set
Implementations§
Source§impl<K: Key> BPlusTreeSet<K>
impl<K: Key> BPlusTreeSet<K>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns key count in the set
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
assert_eq!(set.len(), 0);
set.insert(1);
assert_eq!(set.len(), 1);
set.insert(1);
assert_eq!(set.len(), 1);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the set contains no key
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
assert!(set.is_empty());
set.insert(1);
assert!(!set.is_empty());
Sourcepub fn insert(&mut self, k: K) -> bool
pub fn insert(&mut self, k: K) -> bool
Insert a key into the set Returns true if the key was inserted, false if it already existed
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
assert!(set.insert(1));
assert!(!set.insert(1));
Sourcepub fn remove<Q>(&mut self, k: &Q) -> bool
pub fn remove<Q>(&mut self, k: &Q) -> bool
Remove a key from the set Returns true if the key was removed, false if it didn’t exist
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
set.insert(1);
assert!(set.remove(&1));
assert!(!set.remove(&2));
Sourcepub fn contains<Q>(&self, k: &Q) -> bool
pub fn contains<Q>(&self, k: &Q) -> bool
Returns true if the set contains the key
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
set.insert(1);
assert!(set.contains(&1));
set.remove(&1);
assert!(!set.contains(&1));
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the set
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
set.insert(1);
set.insert(2);
set.clear();
assert!(set.is_empty());
Sourcepub fn first(&self) -> Option<&K>
pub fn first(&self) -> Option<&K>
Returns a reference to the first key in the set, if any
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
assert!(set.first().is_none());
set.insert(1);
set.insert(2);
assert_eq!(*set.first().unwrap(), 1);
Sourcepub fn last(&self) -> Option<&K>
pub fn last(&self) -> Option<&K>
Returns a reference to the last key in the set, if any
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
assert!(set.last().is_none());
set.insert(1);
set.insert(2);
assert_eq!(*set.last().unwrap(), 2);
Sourcepub fn iter(&self) -> Iter<'_, K>
pub fn iter(&self) -> Iter<'_, K>
Returns a iterator over the keys in the set
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<i32>::new();
set.insert(1);
set.insert(2);
let keys = set.iter().collect::<Vec<_>>();
assert_eq!(keys.len(), 2);
Sourcepub fn into_iter(self) -> IntoIter<K>
pub fn into_iter(self) -> IntoIter<K>
Returns a iterator over the keys in the set
§Examples
use sweep_bptree::BPlusTreeSet;
let mut set = BPlusTreeSet::<String>::new();
set.insert(1.to_string());
set.insert(2.to_string());
let keys = set.into_iter().collect::<Vec<_>>();
assert_eq!(keys.len(), 2);
Sourcepub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, K>
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, K>
Visits the elements representing the union,
i.e., all the elements in self
or other
, without duplicates,
in ascending order.
§Examples
use sweep_bptree::BPlusTreeSet;
let mut a = BPlusTreeSet::new();
a.insert(1);
let mut b = BPlusTreeSet::new();
b.insert(1);
b.insert(2);
let union: Vec<_> = a.union(&b).cloned().collect();
assert_eq!(union, [1, 2]);
Trait Implementations§
Source§impl<K: Key> Default for BPlusTreeSet<K>
impl<K: Key> Default for BPlusTreeSet<K>
Source§impl<K: Key> FromIterator<K> for BPlusTreeSet<K>
impl<K: Key> FromIterator<K> for BPlusTreeSet<K>
Source§fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self
Create a BPlusTreeSet from an iterator
§Example
use sweep_bptree::BPlusTreeSet;
let set = BPlusTreeSet::<_>::from_iter(0..1000);
assert_eq!(set.len(), 1000);
assert!(set.contains(&1));
Auto Trait Implementations§
impl<K> !Freeze for BPlusTreeSet<K>
impl<K> RefUnwindSafe for BPlusTreeSet<K>where
K: RefUnwindSafe,
impl<K> Send for BPlusTreeSet<K>where
K: Send,
impl<K> Sync for BPlusTreeSet<K>where
K: Sync,
impl<K> Unpin for BPlusTreeSet<K>
impl<K> UnwindSafe for BPlusTreeSet<K>where
K: UnwindSafe,
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