pub struct BTreeIndexMultiSet<T> { /* private fields */ }Expand description
BTree-based index multi-set.
This is a thin wrapper around
BTreeIndexMultiMap<T, ()> providing a multi-set
API: a value can occur any number of times, every occurrence keeps a
stable index until it (or an earlier entry) is removed, and occurrences
can be iterated either in insertion order or in sorted order.
§Example
use btree_indexmap::BTreeIndexMultiSet;
let mut set = BTreeIndexMultiSet::new();
// Multiple occurrences of the same value, each with its own stable
// index.
set.push_back("apple");
set.push_back("carrot");
set.push_back("apple");
assert_eq!(set.count("apple"), 2);
let apples: Vec<_> = set.get("apple").copied().collect();
assert_eq!(apples, ["apple", "apple"]);
// Iterate in sorted order, occurrences in position order.
let sorted: Vec<_> = set.iter_sorted().copied().collect();
assert_eq!(sorted, ["apple", "apple", "carrot"]);Implementations§
Source§impl<T> BTreeIndexMultiSet<T>
impl<T> BTreeIndexMultiSet<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new, empty multi-set with space reserved for at least
capacity occurrences.
Sourcepub fn singleton(value: T) -> Selfwhere
T: Ord,
pub fn singleton(value: T) -> Selfwhere
T: Ord,
Creates a new multi-set containing the single value.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all occurrences from the set.
This keeps the capacity allocated for the occurrences.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of occurrences the set can hold without reallocating.
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 first(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
Returns a reference to the first occurrence in the set (in insertion order), if any.
Sourcepub fn last(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
Returns a reference to the last occurrence in the set (in insertion order), 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 at least one occurrence of
value.
Sourcepub fn count<Q>(&self, value: &Q) -> usizewhere
Q: ?Sized + Comparable<T>,
pub fn count<Q>(&self, value: &Q) -> usizewhere
Q: ?Sized + Comparable<T>,
Returns the number of occurrences of value in the set.
Sourcepub fn indexes_of<Q>(&self, value: &Q) -> IndexesIter<'_> ⓘwhere
Q: ?Sized + Comparable<T>,
pub fn indexes_of<Q>(&self, value: &Q) -> IndexesIter<'_> ⓘwhere
Q: ?Sized + Comparable<T>,
Returns an iterator over the indexes of every occurrence of value.
Sourcepub fn index_of<Q>(&self, value: &Q) -> Option<usize>where
Q: ?Sized + Comparable<T>,
pub fn index_of<Q>(&self, value: &Q) -> Option<usize>where
Q: ?Sized + Comparable<T>,
Returns the index of the first occurrence of value.
Sourcepub fn get_indexed<Q>(&self, value: &Q) -> GetIndexed<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
pub fn get_indexed<Q>(&self, value: &Q) -> GetIndexed<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
Returns an iterator over (index, &value) for every occurrence of
value.
Sourcepub fn get<Q>(&self, value: &Q) -> Get<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
pub fn get<Q>(&self, value: &Q) -> Get<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
Returns an iterator over a reference to value for every occurrence
found in the set.
Sourcepub fn push_back(&mut self, value: T) -> (usize, bool)where
T: Ord,
pub fn push_back(&mut self, value: T) -> (usize, bool)where
T: Ord,
Inserts a new occurrence of value at the end of the set.
Returns the index of the new occurrence, and whether value was not
already present in the set.
Sourcepub fn push_front(&mut self, value: T) -> boolwhere
T: Ord,
pub fn push_front(&mut self, value: T) -> boolwhere
T: Ord,
Inserts a new occurrence of value at the front of the set.
Returns whether value was not already present in the set.
Sourcepub fn insert_at(&mut self, index: usize, value: T) -> boolwhere
T: Ord,
pub fn insert_at(&mut self, index: usize, value: T) -> boolwhere
T: Ord,
Inserts a new occurrence of value at the given index.
Returns whether value was not already present in the set.
§Panics
Panics if index > len.
Sourcepub fn insert(&mut self, value: T) -> (usize, bool)where
T: Ord,
pub fn insert(&mut self, value: T) -> (usize, bool)where
T: Ord,
Inserts a new occurrence of value in the set, without removing any
existing occurrence.
This is an alias for Self::push_back.
Sourcepub fn shift_remove_at(&mut self, index: usize) -> Option<T>where
T: Ord,
pub fn shift_remove_at(&mut self, index: usize) -> Option<T>where
T: Ord,
Removes the occurrence at the given index, shifting every
following occurrence one index down.
Sourcepub fn swap_remove_at(&mut self, index: usize) -> Option<T>where
T: Ord,
pub fn swap_remove_at(&mut self, index: usize) -> Option<T>where
T: Ord,
Removes the occurrence at the given index, moving the last
occurrence into its place.
Sourcepub fn shift_remove<Q>(&mut self, value: &Q) -> ShiftRemove<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
pub fn shift_remove<Q>(&mut self, value: &Q) -> ShiftRemove<'_, T> ⓘwhere
Q: ?Sized + Comparable<T>,
Removes every occurrence of value, returning an iterator over the
removed occurrences.
Shifts the remaining occurrences down to fill the gaps.
Sourcepub fn swap_remove<Q>(&mut self, value: &Q) -> SwapRemove<'_, T> ⓘ
pub fn swap_remove<Q>(&mut self, value: &Q) -> SwapRemove<'_, T> ⓘ
Removes every occurrence of value, returning an iterator over the
removed occurrences.
Moves occurrences from the end of the set into the gaps.
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 BTreeIndexMultiSet<T>
impl<T: Clone> Clone for BTreeIndexMultiSet<T>
Source§fn clone(&self) -> BTreeIndexMultiSet<T>
fn clone(&self) -> BTreeIndexMultiSet<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 BTreeIndexMultiSet<T>
impl<T: Debug> Debug for BTreeIndexMultiSet<T>
Source§impl<T> Default for BTreeIndexMultiSet<T>
impl<T> Default for BTreeIndexMultiSet<T>
impl<T: Eq> Eq for BTreeIndexMultiSet<T>
Source§impl<T: Ord> Extend<T> for BTreeIndexMultiSet<T>
impl<T: Ord> Extend<T> for BTreeIndexMultiSet<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 BTreeIndexMultiSet<T>
impl<T: Ord> FromIterator<T> for BTreeIndexMultiSet<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 BTreeIndexMultiSet<T>
impl<T: Hash> Hash for BTreeIndexMultiSet<T>
Source§impl<T> Index<usize> for BTreeIndexMultiSet<T>
impl<T> Index<usize> for BTreeIndexMultiSet<T>
Source§impl<T> IntoIterator for BTreeIndexMultiSet<T>
impl<T> IntoIterator for BTreeIndexMultiSet<T>
Source§impl<'a, T> IntoIterator for &'a BTreeIndexMultiSet<T>
impl<'a, T> IntoIterator for &'a BTreeIndexMultiSet<T>
Source§impl<T: Ord> Ord for BTreeIndexMultiSet<T>
impl<T: Ord> Ord for BTreeIndexMultiSet<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 BTreeIndexMultiSet<T>
impl<T: PartialEq> PartialEq for BTreeIndexMultiSet<T>
Source§impl<T: PartialOrd> PartialOrd for BTreeIndexMultiSet<T>
impl<T: PartialOrd> PartialOrd for BTreeIndexMultiSet<T>
Auto Trait Implementations§
impl<T> Freeze for BTreeIndexMultiSet<T>
impl<T> RefUnwindSafe for BTreeIndexMultiSet<T>
impl<T> Send for BTreeIndexMultiSet<T>
impl<T> Sync for BTreeIndexMultiSet<T>
impl<T> Unpin for BTreeIndexMultiSet<T>
impl<T> UnsafeUnpin for BTreeIndexMultiSet<T>
impl<T> UnwindSafe for BTreeIndexMultiSet<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.