pub struct SortedVecSet<T> { /* private fields */ }Expand description
An ordered set built on a SortedVecMap.
SortedVecSet provides a memory-efficient alternative to BTreeSet by wrapping
SortedVecMap<T, ()>.
§Complexity
| Operation | Time Complexity | Space Complexity |
|---|---|---|
new / with_capacity | O(1) | O(1) |
contains / get | O(log N) | O(1) |
insert | O(N) | O(1) amortized |
remove | O(N) | O(1) |
union / difference | O(N + M) | O(1) |
§When to use
- Similar to
SortedVecMap, it is ideal for read-heavy, memory-constrained sets.
Implementations§
Source§impl<T> SortedVecSet<T>
impl<T> SortedVecSet<T>
Sourcepub fn builder() -> SortedVecSetBuilder<T>
pub fn builder() -> SortedVecSetBuilder<T>
Returns a new builder for SortedVecSet.
Sourcepub fn builder_with_capacity(capacity: usize) -> SortedVecSetBuilder<T>
pub fn builder_with_capacity(capacity: usize) -> SortedVecSetBuilder<T>
Returns a new builder for SortedVecSet with at least the specified capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the set can hold without reallocating.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty SortedVecSet with at least the specified capacity.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements in the SortedVecSet.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the set as much as possible.
Sourcepub fn contains<Q>(&self, value: &Q) -> bool
pub fn contains<Q>(&self, value: &Q) -> bool
Returns true if the set contains the given value.
Complexity: O(log n) time.
Sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
Returns a reference to the value in the set, if any, that is equal to the given value.
Complexity: O(log n) time.
Sourcepub fn insert(&mut self, value: T) -> boolwhere
T: Ord,
pub fn insert(&mut self, value: T) -> boolwhere
T: Ord,
Inserts a value into the set. Returns true if the value was not already present.
Complexity: O(log n) search time, plus O(n) time to insert the element if it is not present.
Sourcepub fn remove<Q>(&mut self, value: &Q) -> bool
pub fn remove<Q>(&mut self, value: &Q) -> bool
Removes a value from the set. Returns true if the value was present.
Complexity: O(log n) search time, plus O(n) time to remove the element if it is present.
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Returns an iterator over the elements of the set, in sorted order.
Sourcepub fn range<Q, R>(&self, range: R) -> Range<'_, T> ⓘ
pub fn range<Q, R>(&self, range: R) -> Range<'_, T> ⓘ
Constructs a double-ended iterator over a sub-range of elements in the set.
Complexity: O(log n) to find the start and end of the range.
Sourcepub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T> ⓘwhere
T: Ord,
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T> ⓘwhere
T: Ord,
Returns an iterator yielding elements from both sets in sorted order, without duplicates.
Complexity: O(N + M) where N is the number of elements in self and M is the number of elements in other.
Sourcepub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T> ⓘwhere
T: Ord,
pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T> ⓘwhere
T: Ord,
Returns an iterator yielding elements in self that are not in other.
Complexity: O(N + M) where N is the number of elements in self and M is the number of elements in other.
Trait Implementations§
Source§impl<T: Clone> Clone for SortedVecSet<T>
impl<T: Clone> Clone for SortedVecSet<T>
Source§fn clone(&self) -> SortedVecSet<T>
fn clone(&self) -> SortedVecSet<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for SortedVecSet<T>
impl<T: Debug> Debug for SortedVecSet<T>
Source§impl<T> Default for SortedVecSet<T>
impl<T> Default for SortedVecSet<T>
Source§impl<'de, T> Deserialize<'de> for SortedVecSet<T>where
T: Ord + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for SortedVecSet<T>where
T: Ord + Deserialize<'de>,
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T: Ord> Extend<T> for SortedVecSet<T>
impl<T: Ord> Extend<T> for SortedVecSet<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends the set with the contents of an iterator.
Complexity: O(n log n) where n is the total number of elements, or O(n) if the
iterator yields elements in sorted order and they are all greater than the existing
elements.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> From<SortedVecSet<T>> for Vec<T>
impl<T> From<SortedVecSet<T>> for Vec<T>
Source§fn from(set: SortedVecSet<T>) -> Self
fn from(set: SortedVecSet<T>) -> Self
Source§impl<T: Ord> FromIterator<T> for SortedVecSet<T>
impl<T: Ord> FromIterator<T> for SortedVecSet<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Constructs a SortedVecSet from an iterator.
Complexity: O(n log n) where n is the number of elements in the iterator,
or O(n) if the elements are already sorted.