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§
Source§impl<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) -> 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
.
Sourcepub fn contains<Q>(&self, key: &Q) -> bool
pub fn contains<Q>(&self, key: &Q) -> bool
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>(&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.
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>(&self, key: &Q) -> Option<(usize, &T)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &T)>
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>(&self, key: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
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
pub fn insert(&mut self, value: T) -> bool
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)
pub fn insert_full(&mut self, value: T) -> (usize, bool)
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§
Source§impl<'de, T> Deserialize<'de> for IndexSet<T>
Requires crate feature "serde"
impl<'de, T> Deserialize<'de> for IndexSet<T>
Requires crate feature "serde"
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<'a, T> Extend<&'a T> for IndexSet<T>
impl<'a, T> Extend<&'a T> for IndexSet<T>
Source§fn 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>,
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> Extend<T> for IndexSet<T>
impl<T> Extend<T> for IndexSet<T>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
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
)