indexmap_nostd::set

Struct 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 require K: 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 of HashMap which has the effect that methods no longer require K: Hash but K: Ord instead.

Implementations§

Source§

impl<T> IndexSet<T>

Source

pub fn new() -> Self

Makes a new, empty IndexSet.

Does not allocate anything on its own.

Source

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.

Source

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

Reserve capacity for at least additional more values.

Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

Source

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.

Source

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.

Source

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source

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

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.

Source

pub fn get_index(&self, index: usize) -> Option<&T>

Returns a shared reference to the value at the given index.

Source

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.
Source

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.
Source

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

Gets an iterator that visits the elements in the IndexSet in the order in which they have been inserted into the set unless there have been removals.

Source

pub fn clear(&mut self)

Clears the set, removing all elements.

Trait Implementations§

Source§

impl<T: Clone> Clone for IndexSet<T>

Source§

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

Returns a copy 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 IndexSet<T>

Source§

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

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

impl<T> Default for IndexSet<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for IndexSet<T>
where T: Deserialize<'de> + Ord + Clone,

Requires crate feature "serde"

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<'a, T> Extend<&'a T> for IndexSet<T>
where T: Ord + Copy,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = &'a T>,

Extends a collection with the contents of an iterator. Read more
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> Extend<T> for IndexSet<T>
where T: Ord + Clone,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
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, const N: usize> From<[T; N]> for IndexSet<T>
where T: Ord + Clone,

Source§

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

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for IndexSet<T>
where T: Ord + Clone,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for IndexSet<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'de, T, E> IntoDeserializer<'de, E> for IndexSet<T>
where T: IntoDeserializer<'de, E> + Ord, E: Error,

Source§

type Deserializer = SeqDeserializer<<IndexSet<T> as IntoIterator>::IntoIter, E>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'a, T> IntoIterator for &'a IndexSet<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 IndexSet<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 IndexSet<T>

Source§

fn cmp(&self, other: &IndexSet<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 IndexSet<T>

Source§

fn eq(&self, other: &IndexSet<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 IndexSet<T>

Source§

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 · 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 for IndexSet<T>
where T: Serialize + Ord,

Requires crate feature "serde"

Source§

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

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

impl<T: Eq> Eq for IndexSet<T>

Source§

impl<T> StructuralPartialEq for IndexSet<T>

Auto Trait Implementations§

§

impl<T> Freeze for IndexSet<T>

§

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>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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>,