Struct indexmap_nostd::set::IndexSet
source · [−]pub struct IndexSet<T> { /* private fields */ }
Expand description
A b-tree set where the iteration order of the values is independent of the ordering of the values.
The interface is closely compatible with the indexmap
crate
and a subset of the features that is relevant for the
wasmparser-nostd
crate.
Differences to original IndexSet
Since the goal of this crate was to maintain a simple
no_std
compatible fork of the indexmap
crate there are some
downsides and differences.
- Some operations such as
IndexSet::insert
now requireK: Clone
. - It is to be expected that this fork performs worse than the original
indexmap
crate implementation. - The implementation is based on
BTreeMap
internally instead ofHashMap
which has the effect that methods no longer requireK: Hash
butK: Ord
instead.
Implementations
sourceimpl<T> IndexSet<T>
impl<T> IndexSet<T>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty IndexSet
with at least the specified capacity.
Does not allocate if capacity
is zero.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve capacity for at least additional
more values.
sourcepub fn is_disjoint(&self, other: &Self) -> bool where
T: Ord,
pub fn is_disjoint(&self, other: &Self) -> bool where
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) -> bool where
T: Ord,
pub fn is_subset(&self, other: &Self) -> bool where
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) -> bool where
T: Ord,
pub fn is_superset(&self, other: &Self) -> bool where
T: Ord,
Returns true
if the set is a superset of another,
i.e., self
contains at least all the elements in other
.
sourcepub fn contains<Q: ?Sized>(&self, key: &Q) -> bool where
T: Borrow<Q> + Ord,
Q: Ord,
pub fn contains<Q: ?Sized>(&self, key: &Q) -> bool where
T: Borrow<Q> + Ord,
Q: Ord,
Returns true
if the set contains an element equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
sourcepub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord,
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord,
Returns a reference to the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
sourcepub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(usize, &T)> where
T: Borrow<Q> + Ord,
Q: Ord,
pub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(usize, &T)> where
T: Borrow<Q> + Ord,
Q: Ord,
Returns the index-value pair corresponding to the supplied value.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize> where
T: Borrow<Q> + Ord,
Q: Ord,
pub fn get_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize> where
T: Borrow<Q> + Ord,
Q: Ord,
Returns the unique index corresponding to the supplied value.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_index(&self, index: usize) -> Option<&T>
pub fn get_index(&self, index: usize) -> Option<&T>
Returns a shared reference to the value at the given index.
sourcepub fn insert(&mut self, value: T) -> bool where
T: Ord + Clone,
pub fn insert(&mut self, value: T) -> bool where
T: Ord + Clone,
Adds a value to the set.
Returns whether the value was newly inserted. That is:
- If the set did not previously contain an equal value,
true
is returned. - If the set already contained an equal value,
false
is returned, and the entry is not updated.
sourcepub fn insert_full(&mut self, value: T) -> (usize, bool) where
T: Ord + Clone,
pub fn insert_full(&mut self, value: T) -> (usize, bool) where
T: Ord + Clone,
Adds a value to the set.
Returns the unique index to the value as well as a bool
flag telling
whether the value was newly inserted. That is:
- If the set did not previously contain an equal value,
true
is returned. - If the set already contained an equal value,
false
is returned, and the entry is not updated.
Trait Implementations
sourceimpl<'de, T> Deserialize<'de> for IndexSet<T> where
T: Deserialize<'de> + Ord + Clone,
impl<'de, T> Deserialize<'de> for IndexSet<T> where
T: Deserialize<'de> + Ord + Clone,
Requires crate feature "serde"
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a, T> Extend<&'a T> for IndexSet<T> where
T: Ord + Copy,
impl<'a, T> Extend<&'a T> for IndexSet<T> where
T: Ord + Copy,
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> Extend<T> for IndexSet<T> where
T: Ord + Clone,
impl<T> Extend<T> for IndexSet<T> where
T: Ord + Clone,
sourcefn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> FromIterator<T> for IndexSet<T> where
T: Ord + Clone,
impl<T> FromIterator<T> for IndexSet<T> where
T: Ord + Clone,
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
sourceimpl<'de, T, E> IntoDeserializer<'de, E> for IndexSet<T> where
T: IntoDeserializer<'de, E> + Ord,
E: Error,
impl<'de, T, E> IntoDeserializer<'de, E> for IndexSet<T> where
T: IntoDeserializer<'de, E> + Ord,
E: Error,
type Deserializer = SeqDeserializer<<IndexSet<T> as IntoIterator>::IntoIter, E>
type Deserializer = SeqDeserializer<<IndexSet<T> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.
sourcefn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Convert this value into a deserializer.
sourceimpl<'a, T> IntoIterator for &'a IndexSet<T>
impl<'a, T> IntoIterator for &'a IndexSet<T>
sourceimpl<T> IntoIterator for IndexSet<T>
impl<T> IntoIterator for IndexSet<T>
sourceimpl<T: Ord> Ord for IndexSet<T>
impl<T: Ord> Ord for IndexSet<T>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T: PartialEq> PartialEq<IndexSet<T>> for IndexSet<T>
impl<T: PartialEq> PartialEq<IndexSet<T>> for IndexSet<T>
sourceimpl<T: PartialOrd> PartialOrd<IndexSet<T>> for IndexSet<T>
impl<T: PartialOrd> PartialOrd<IndexSet<T>> for IndexSet<T>
sourcefn partial_cmp(&self, other: &IndexSet<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &IndexSet<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Eq> Eq for IndexSet<T>
impl<T> StructuralEq for IndexSet<T>
impl<T> StructuralPartialEq for IndexSet<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for IndexSet<T> where
T: RefUnwindSafe,
impl<T> Send for IndexSet<T> where
T: Send,
impl<T> Sync for IndexSet<T> where
T: Sync,
impl<T> Unpin for IndexSet<T> where
T: Unpin,
impl<T> UnwindSafe for IndexSet<T> where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more