pub struct BTreeIndexSet<T> { /* private fields */ }Expand description
BTree-based index set.
This is a thin wrapper around BTreeIndexMap<T, ()>
providing a set-like API: every value is stored at most once, values keep
a stable index until they (or an earlier value) are removed, and values
can be iterated either in insertion order or in sorted order.
§Example
use btree_indexmap::BTreeIndexSet;
let mut set = BTreeIndexSet::new();
// Values are stored in insertion order and assigned a stable index.
assert!(set.insert("banana"));
assert!(set.insert("apple"));
assert!(!set.insert("banana")); // already present
// O(1) access by index (insertion order).
assert_eq!(set.as_slice(), ["banana", "apple"]);
// O(log n) lookup, returning the stable index alongside the value.
assert_eq!(set.get_full("apple"), Some((1, &"apple")));
// Iterate in sorted order.
let sorted: Vec<_> = set.iter_sorted().copied().collect();
assert_eq!(sorted, ["apple", "banana"]);Implementations§
Source§impl<T> BTreeIndexSet<T>
impl<T> BTreeIndexSet<T>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all values from the set.
This keeps the capacity allocated for the values.
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns the values of the set as a slice, in insertion (index) order.
Sourcepub fn get_full<Q>(&self, value: &Q) -> Option<(usize, &T)>where
Q: ?Sized + Comparable<T>,
pub fn get_full<Q>(&self, value: &Q) -> Option<(usize, &T)>where
Q: ?Sized + Comparable<T>,
Returns the index and a reference to the value equal to value, if
any.
Sourcepub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>where
Q: ?Sized + Comparable<T>,
pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>where
Q: ?Sized + Comparable<T>,
Returns the index of value in the set, if any.
Sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>where
Q: ?Sized + Comparable<T>,
pub fn get<Q>(&self, value: &Q) -> Option<&T>where
Q: ?Sized + Comparable<T>,
Returns a reference to the value equal to value, if any.
Sourcepub fn contains<Q>(&self, value: &Q) -> boolwhere
Q: ?Sized + Comparable<T>,
pub fn contains<Q>(&self, value: &Q) -> boolwhere
Q: ?Sized + Comparable<T>,
Returns true if the set contains value.
Sourcepub fn insert_full(&mut self, value: T) -> (usize, bool)where
T: Ord,
pub fn insert_full(&mut self, value: T) -> (usize, bool)where
T: Ord,
Inserts value in the set, returning its index and whether it was
newly inserted (true) or already present (false).
Sourcepub fn insert(&mut self, value: T) -> boolwhere
T: Ord,
pub fn insert(&mut self, value: T) -> boolwhere
T: Ord,
Inserts value in the set, returning whether it was newly inserted.
Sourcepub fn shift_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>where
Q: ?Sized + Comparable<T>,
pub fn shift_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>where
Q: ?Sized + Comparable<T>,
Removes value from the set, returning its former index and the
value itself, if it was present.
Shifts every following value one index down.
Sourcepub fn shift_take<Q>(&mut self, value: &Q) -> Option<T>where
Q: ?Sized + Comparable<T>,
pub fn shift_take<Q>(&mut self, value: &Q) -> Option<T>where
Q: ?Sized + Comparable<T>,
Removes value from the set, returning the removed value, if any.
Shifts every following value one index down.
Sourcepub fn shift_remove<Q>(&mut self, value: &Q) -> boolwhere
Q: ?Sized + Comparable<T>,
pub fn shift_remove<Q>(&mut self, value: &Q) -> boolwhere
Q: ?Sized + Comparable<T>,
Removes value from the set, returning whether the value was
present.
Shifts every following value one index down.
Sourcepub fn swap_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>
pub fn swap_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>
Removes value from the set, returning its former index and the
value itself, if it was present.
Moves the last value into the removed slot.
Sourcepub fn swap_take<Q>(&mut self, value: &Q) -> Option<T>
pub fn swap_take<Q>(&mut self, value: &Q) -> Option<T>
Removes value from the set, returning the removed value, if any.
Moves the last value into its place.
Sourcepub fn swap_remove<Q>(&mut self, value: &Q) -> bool
pub fn swap_remove<Q>(&mut self, value: &Q) -> bool
Removes value from the set, returning whether the value was
present.
Moves the last value into its place.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over the values of the set, in insertion (index) order.
Sourcepub fn iter_sorted(&self) -> IterSorted<'_, T> ⓘ
pub fn iter_sorted(&self) -> IterSorted<'_, T> ⓘ
Returns an iterator over the values of the set, sorted according to
T’s implementation of Ord.
Sourcepub fn into_iter_sorted(self) -> IntoIterSorted<T> ⓘ
pub fn into_iter_sorted(self) -> IntoIterSorted<T> ⓘ
Turns this set into an iterator over its values, sorted according to
T’s implementation of Ord.
Trait Implementations§
Source§impl<T: Clone> Clone for BTreeIndexSet<T>
impl<T: Clone> Clone for BTreeIndexSet<T>
Source§fn clone(&self) -> BTreeIndexSet<T>
fn clone(&self) -> BTreeIndexSet<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for BTreeIndexSet<T>
impl<T: Debug> Debug for BTreeIndexSet<T>
Source§impl<T> Default for BTreeIndexSet<T>
impl<T> Default for BTreeIndexSet<T>
impl<T: Eq> Eq for BTreeIndexSet<T>
Source§impl<T: Ord> Extend<T> for BTreeIndexSet<T>
impl<T: Ord> Extend<T> for BTreeIndexSet<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T: Ord> FromIterator<T> for BTreeIndexSet<T>
impl<T: Ord> FromIterator<T> for BTreeIndexSet<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Source§impl<T: Hash> Hash for BTreeIndexSet<T>
impl<T: Hash> Hash for BTreeIndexSet<T>
Source§impl<T> Index<usize> for BTreeIndexSet<T>
impl<T> Index<usize> for BTreeIndexSet<T>
Source§impl<T> IntoIterator for BTreeIndexSet<T>
impl<T> IntoIterator for BTreeIndexSet<T>
Source§impl<'a, T> IntoIterator for &'a BTreeIndexSet<T>
impl<'a, T> IntoIterator for &'a BTreeIndexSet<T>
Source§impl<T: Ord> Ord for BTreeIndexSet<T>
impl<T: Ord> Ord for BTreeIndexSet<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for BTreeIndexSet<T>
impl<T: PartialEq> PartialEq for BTreeIndexSet<T>
Source§impl<T: PartialOrd> PartialOrd for BTreeIndexSet<T>
impl<T: PartialOrd> PartialOrd for BTreeIndexSet<T>
Auto Trait Implementations§
impl<T> Freeze for BTreeIndexSet<T>
impl<T> RefUnwindSafe for BTreeIndexSet<T>
impl<T> Send for BTreeIndexSet<T>
impl<T> Sync for BTreeIndexSet<T>
impl<T> Unpin for BTreeIndexSet<T>
impl<T> UnsafeUnpin for BTreeIndexSet<T>
impl<T> UnwindSafe for BTreeIndexSet<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.