Skip to main content

SortedVecSet

Struct SortedVecSet 

Source
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

OperationTime ComplexitySpace Complexity
new / with_capacityO(1)O(1)
contains / getO(log N)O(1)
insertO(N)O(1) amortized
removeO(N)O(1)
union / differenceO(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>

Source

pub fn builder() -> SortedVecSetBuilder<T>

Returns a new builder for SortedVecSet.

Source

pub fn builder_with_capacity(capacity: usize) -> SortedVecSetBuilder<T>

Returns a new builder for SortedVecSet with at least the specified capacity.

Source

pub fn new() -> Self

Constructs a new, empty SortedVecSet.

Source

pub fn capacity(&self) -> usize

Returns the number of elements the set can hold without reallocating.

Source

pub fn with_capacity(capacity: usize) -> Self

Constructs a new, empty SortedVecSet with at least the specified capacity.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements in the SortedVecSet.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the set as much as possible.

Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no elements in the set.

Source

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

Returns true if the set contains the given value.

Complexity: O(log n) time.

Source

pub fn get<Q>(&self, value: &Q) -> Option<&T>
where T: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns a reference to the value in the set, if any, that is equal to the given value.

Complexity: O(log n) time.

Source

pub fn insert(&mut self, value: T) -> bool
where 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.

Source

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

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.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the elements of the set, in sorted order.

Source

pub fn range<Q, R>(&self, range: R) -> Range<'_, T>
where T: Borrow<Q> + Ord, Q: Ord + ?Sized, R: RangeBounds<Q>,

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> SortedVecSet<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for SortedVecSet<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for SortedVecSet<T>

Source§

fn default() -> Self

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

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Ord> Extend<T> for SortedVecSet<T>

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: Ord, const N: usize> From<[T; N]> for SortedVecSet<T>

Source§

fn from(arr: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T: Ord> From<BTreeSet<T>> for SortedVecSet<T>

Source§

fn from(set: BTreeSet<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<SortedVecSet<T>> for Vec<T>

Source§

fn from(set: SortedVecSet<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Ord> From<Vec<T>> for SortedVecSet<T>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Ord> FromIterator<T> for SortedVecSet<T>

Source§

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.

Source§

impl<T: Hash> Hash for SortedVecSet<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T> IntoIterator for &'a SortedVecSet<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for SortedVecSet<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Ord> Ord for SortedVecSet<T>

Source§

fn cmp(&self, other: &SortedVecSet<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for SortedVecSet<T>

Source§

fn eq(&self, other: &SortedVecSet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for SortedVecSet<T>

Source§

fn partial_cmp(&self, other: &SortedVecSet<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Serialize> Serialize for SortedVecSet<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Eq> Eq for SortedVecSet<T>

Source§

impl<T> StructuralPartialEq for SortedVecSet<T>

Auto Trait Implementations§

§

impl<T> Freeze for SortedVecSet<T>

§

impl<T> RefUnwindSafe for SortedVecSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for SortedVecSet<T>
where T: Send,

§

impl<T> Sync for SortedVecSet<T>
where T: Sync,

§

impl<T> Unpin for SortedVecSet<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for SortedVecSet<T>

§

impl<T> UnwindSafe for SortedVecSet<T>
where T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,