Struct BPlusTreeSet

Source
pub struct BPlusTreeSet<K: Key> { /* private fields */ }
Expand description

A B+ tree based set

Implementations§

Source§

impl<K: Key> BPlusTreeSet<K>

Source

pub fn new() -> Self

Create a new BPlusTreeSet

§Examples
use sweep_bptree::BPlusTreeSet;

BPlusTreeSet::<i32>::new();
Source

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);
Source

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());
Source

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));
Source

pub fn remove<Q>(&mut self, k: &Q) -> bool
where Q: Ord + ?Sized, K: Borrow<Q>,

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));
Source

pub fn contains<Q>(&self, k: &Q) -> bool
where Q: Ord + ?Sized, K: Borrow<Q>,

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));
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Key> FromIterator<K> for BPlusTreeSet<K>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.