pub struct FrozenSet<T> { /* private fields */ }Expand description
A compact frozen (immutable) ordered set backed by a FrozenMap<T, ()>.
This is a read-only set that stores elements in a contiguous, sorted array. It provides efficient binary search lookups and iteration, but cannot be modified after construction.
§Construction
If you’re building a new set, and you don’t expect many overlapping items, consider pushing
items into a Vec and calling FrozenSet::from or using the FromIterator
implementation via Iterator::collect. It is typically cheaper to collect into a Vec and
sort the items once at the end than it is to maintain a temporary set data structure.
If you already have a set, or you have many overlapping items that you don’t want to temporarily
hold onto, you can use the From or Into traits to create a FrozenSet from one of
many common collections. You should prefer using a BTreeSet, as it matches the sorted
semantics of FrozenSet and avoids a sort operation during conversion.
Overlapping items encountered during construction preserve the last overlapping item, matching similar behavior for other sets in the standard library.
Similar to the API of BTreeSet, there are no convenience methods for constructing from a
Vec or boxed slice. Because of limitations of the internal representation and Rust’s memory
layout rules, the most efficient way to convert from these data structures is via an
Iterator.
Implementations§
Source§impl<T> FrozenSet<T>where
T: Ord,
impl<T> FrozenSet<T>where
T: Ord,
Sourcepub fn from_unique_sorted_iter(items: impl IntoIterator<Item = T>) -> Self
pub fn from_unique_sorted_iter(items: impl IntoIterator<Item = T>) -> Self
Creates a FrozenSet from a pre-sorted iterator with unique items.
This is more efficient than Iterator::collect or FromIterator::from_iter if you know
that the iterator is sorted and has no overlapping items.
Panics if the items are not unique and sorted.
Sourcepub fn from_unique_sorted_iter_unchecked(
items: impl IntoIterator<Item = T>,
) -> Self
pub fn from_unique_sorted_iter_unchecked( items: impl IntoIterator<Item = T>, ) -> Self
Creates a FrozenSet from a pre-sorted iterator with unique items.
This is more efficient than Iterator::collect or FromIterator::from_iter if you know
that the iterator is sorted and has no overlapping items.
§Correctness
The caller must ensure that:
- The iterator yields items in ascending order according to
T: Ord - There are no overlapping items
If these invariants are not upheld, the set will behave incorrectly (e.g.,
FrozenSet::contains may fail to find items that are present), but no memory unsafety
will occur.
When debug_assertions is enabled, this will panic if an invariant is not upheld.
Source§impl<T> FrozenSet<T>
impl<T> FrozenSet<T>
Sourcepub fn contains<Q>(&self, value: &Q) -> bool
pub fn contains<Q>(&self, value: &Q) -> bool
Returns true if the set contains an element equal to the value.
Sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
Returns a reference to the element in the set, if any, that is equal to the value.
Sourcepub fn first(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
Returns a reference to the first element in the set, if any. This element is always the minimum of all elements in the set.
Sourcepub fn last(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
Returns a reference to the last element in the set, if any. This element is always the maximum of all elements in the set.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Gets an iterator that visits the elements in the FrozenSet in ascending 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.
Sourcepub fn is_disjoint(&self, other: &Self) -> boolwhere
T: Ord,
pub fn is_disjoint(&self, other: &Self) -> boolwhere
T: Ord,
Returns true if self has no elements in common with other. This is equivalent to
checking for an empty intersection.
Sourcepub fn is_subset(&self, other: &Self) -> boolwhere
T: Ord,
pub fn is_subset(&self, other: &Self) -> boolwhere
T: Ord,
Returns true if the set is a subset of another, i.e., other contains at least all the
elements in self.
Sourcepub fn is_superset(&self, other: &Self) -> boolwhere
T: Ord,
pub fn is_superset(&self, other: &Self) -> boolwhere
T: Ord,
Returns true if the set is a superset of another, i.e., self contains at least all the
elements in other.
Trait Implementations§
Source§impl<'__de, T, __Context> BorrowDecode<'__de, __Context> for FrozenSet<T>where
T: BorrowDecode<'__de, __Context> + '__de,
impl<'__de, T, __Context> BorrowDecode<'__de, __Context> for FrozenSet<T>where
T: BorrowDecode<'__de, __Context> + '__de,
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl<'de, T> Deserialize<'de> for FrozenSet<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for FrozenSet<T>where
T: 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> FromIterator<T> for FrozenSet<T>
impl<T: Ord> FromIterator<T> for FrozenSet<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(items: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(items: I) -> Self
Creates a FrozenSet from an iterator of items. If there are overlapping items, only the
last copy is kept.
Source§impl<'a, T> IntoIterator for &'a FrozenSet<T>
impl<'a, T> IntoIterator for &'a FrozenSet<T>
Source§impl<T> IntoIterator for FrozenSet<T>
impl<T> IntoIterator for FrozenSet<T>
Source§impl<T: Ord> Ord for FrozenSet<T>
impl<T: Ord> Ord for FrozenSet<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd> PartialOrd for FrozenSet<T>
impl<T: PartialOrd> PartialOrd for FrozenSet<T>
impl<T: Eq> Eq for FrozenSet<T>
impl<T> StructuralPartialEq for FrozenSet<T>
Auto Trait Implementations§
impl<T> Freeze for FrozenSet<T>
impl<T> RefUnwindSafe for FrozenSet<T>where
T: RefUnwindSafe,
impl<T> Send for FrozenSet<T>where
T: Send,
impl<T> Sync for FrozenSet<T>where
T: Sync,
impl<T> Unpin for FrozenSet<T>
impl<T> UnwindSafe for FrozenSet<T>where
T: UnwindSafe,
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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.