[][src]Struct indexmap::set::IndexSet

pub struct IndexSet<T, S = RandomState> { /* fields omitted */ }

A hash set where the iteration order of the values is independent of their hash values.

The interface is closely compatible with the standard HashSet, but also has additional features.

Order

The values have a consistent order that is determined by the sequence of insertion and removal calls on the set. The order does not depend on the values or the hash function at all. Note that insertion order and value are not affected if a re-insertion is attempted once an element is already present.

All iterators traverse the set in order. Set operation iterators like union produce a concatenated order, as do their matching "bitwise" operators. See their documentation for specifics.

The insertion order is preserved, with notable exceptions like the .remove() or .swap_remove() methods. Methods such as .sort_by() of course result in a new order, depending on the sorting order.

Indices

The values are indexed in a compact range without holes in the range 0..self.len(). For example, the method .get_full looks up the index for a value, and the method .get_index looks up the value by index.

Examples

use indexmap::IndexSet;

// Collects which letters appear in a sentence.
let letters: IndexSet<_> = "a short treatise on fungi".chars().collect();
 
assert!(letters.contains(&'s'));
assert!(letters.contains(&'t'));
assert!(letters.contains(&'u'));
assert!(!letters.contains(&'y'));

Methods

impl<T> IndexSet<T>[src]

pub fn new() -> Self[src]

Create a new set. (Does not allocate.)

pub fn with_capacity(n: usize) -> Self[src]

Create a new set with capacity for n elements. (Does not allocate if n is zero.)

Computes in O(n) time.

impl<T, S> IndexSet<T, S>[src]

pub fn with_capacity_and_hasher(n: usize, hash_builder: S) -> Self where
    S: BuildHasher
[src]

Create a new set with capacity for n elements. (Does not allocate if n is zero.)

Computes in O(n) time.

pub fn len(&self) -> usize[src]

Return the number of elements in the set.

Computes in O(1) time.

pub fn is_empty(&self) -> bool[src]

Returns true if the set contains no elements.

Computes in O(1) time.

pub fn with_hasher(hash_builder: S) -> Self where
    S: BuildHasher
[src]

Create a new set with hash_builder

pub fn hasher(&self) -> &S where
    S: BuildHasher
[src]

Return a reference to the set's BuildHasher.

pub fn capacity(&self) -> usize[src]

Computes in O(1) time.

impl<T, S> IndexSet<T, S> where
    T: Hash + Eq,
    S: BuildHasher
[src]

pub fn clear(&mut self)[src]

Remove all elements in the set, while preserving its capacity.

Computes in O(n) time.

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

FIXME Not implemented fully yet

pub fn insert(&mut self, value: T) -> bool[src]

Insert the value into the set.

If an equivalent item already exists in the set, it returns false leaving the original value in the set and without altering its insertion order. Otherwise, it inserts the new item and returns true.

Computes in O(1) time (amortized average).

pub fn insert_full(&mut self, value: T) -> (usize, bool)[src]

Insert the value into the set, and get its index.

If an equivalent item already exists in the set, it returns the index of the existing item and false, leaving the original value in the set and without altering its insertion order. Otherwise, it inserts the new item and returns the index of the inserted item and true.

Computes in O(1) time (amortized average).

Important traits for Iter<'a, T>
pub fn iter(&self) -> Iter<T>[src]

Return an iterator over the values of the set, in their order

Important traits for Difference<'a, T, S>
pub fn difference<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> Difference<'a, T, S2> where
    S2: BuildHasher
[src]

Return an iterator over the values that are in self but not other.

Values are produced in the same order that they appear in self.

Important traits for SymmetricDifference<'a, T, S1, S2>
pub fn symmetric_difference<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> SymmetricDifference<'a, T, S, S2> where
    S2: BuildHasher
[src]

Return an iterator over the values that are in self or other, but not in both.

Values from self are produced in their original order, followed by values from other in their original order.

Important traits for Intersection<'a, T, S>
pub fn intersection<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> Intersection<'a, T, S2> where
    S2: BuildHasher
[src]

Return an iterator over the values that are in both self and other.

Values are produced in the same order that they appear in self.

Important traits for Union<'a, T, S>
pub fn union<'a, S2>(&'a self, other: &'a IndexSet<T, S2>) -> Union<'a, T, S> where
    S2: BuildHasher
[src]

Return an iterator over all values that are in self or other.

Values from self are produced in their original order, followed by values that are unique to other in their original order.

pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool where
    Q: Hash + Equivalent<T>, 
[src]

Return true if an equivalent to value exists in the set.

Computes in O(1) time (average).

pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T> where
    Q: Hash + Equivalent<T>, 
[src]

Return a reference to the value stored in the set, if it is present, else None.

Computes in O(1) time (average).

pub fn get_full<Q: ?Sized>(&self, value: &Q) -> Option<(usize, &T)> where
    Q: Hash + Equivalent<T>, 
[src]

Return item index and value

pub fn replace(&mut self, value: T) -> Option<T>[src]

Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.

Computes in O(1) time (average).

pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool where
    Q: Hash + Equivalent<T>, 
[src]

Deprecated:

use swap_remove or shift_remove

FIXME Same as .swap_remove

Computes in O(1) time (average).

pub fn swap_remove<Q: ?Sized>(&mut self, value: &Q) -> bool where
    Q: Hash + Equivalent<T>, 
[src]

Remove the value from the set, and return true if it was present.

Like Vec::swap_remove, the value is removed by swapping it with the last element of the set and popping it off. This perturbs the postion of what used to be the last element!

Return false if value was not in the set.

Computes in O(1) time (average).

pub fn shift_remove<Q: ?Sized>(&mut self, value: &Q) -> bool where
    Q: Hash + Equivalent<T>, 
[src]

Remove the value from the set, and return true if it was present.

Like Vec::remove, the value is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

Return false if value was not in the set.

Computes in O(n) time (average).

pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T> where
    Q: Hash + Equivalent<T>, 
[src]

Deprecated:

use swap_take or shift_take

FIXME Same as .swap_take

Computes in O(1) time (average).

pub fn swap_take<Q: ?Sized>(&mut self, value: &Q) -> Option<T> where
    Q: Hash + Equivalent<T>, 
[src]

Removes and returns the value in the set, if any, that is equal to the given one.

Like Vec::swap_remove, the value is removed by swapping it with the last element of the set and popping it off. This perturbs the postion of what used to be the last element!

Return None if value was not in the set.

Computes in O(1) time (average).

pub fn shift_take<Q: ?Sized>(&mut self, value: &Q) -> Option<T> where
    Q: Hash + Equivalent<T>, 
[src]

Removes and returns the value in the set, if any, that is equal to the given one.

Like Vec::remove, the value is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

Return None if value was not in the set.

Computes in O(n) time (average).

pub fn swap_remove_full<Q: ?Sized>(&mut self, value: &Q) -> Option<(usize, T)> where
    Q: Hash + Equivalent<T>, 
[src]

Remove the value from the set return it and the index it had.

Like Vec::swap_remove, the value is removed by swapping it with the last element of the set and popping it off. This perturbs the postion of what used to be the last element!

Return None if value was not in the set.

pub fn shift_remove_full<Q: ?Sized>(&mut self, value: &Q) -> Option<(usize, T)> where
    Q: Hash + Equivalent<T>, 
[src]

Remove the value from the set return it and the index it had.

Like Vec::remove, the value is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

Return None if value was not in the set.

pub fn pop(&mut self) -> Option<T>[src]

Remove the last value

Computes in O(1) time (average).

pub fn retain<F>(&mut self, keep: F) where
    F: FnMut(&T) -> bool
[src]

Scan through each value in the set and keep those where the closure keep returns true.

The elements are visited in order, and remaining elements keep their order.

Computes in O(n) time (average).

pub fn sort(&mut self) where
    T: Ord
[src]

Sort the set’s values by their default ordering.

See sort_by for details.

pub fn sort_by<F>(&mut self, compare: F) where
    F: FnMut(&T, &T) -> Ordering
[src]

Sort the set’s values in place using the comparison function compare.

Computes in O(n log n) time and O(n) space. The sort is stable.

Important traits for IntoIter<T>
pub fn sorted_by<F>(self, cmp: F) -> IntoIter<T> where
    F: FnMut(&T, &T) -> Ordering
[src]

Sort the values of the set and return a by value iterator of the values with the result.

The sort is stable.

Important traits for Drain<'a, T>
pub fn drain(&mut self, range: RangeFull) -> Drain<T>[src]

Clears the IndexSet, returning all values as a drain iterator. Keeps the allocated memory for reuse.

impl<T, S> IndexSet<T, S>[src]

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

Get a value by index

Valid indices are 0 <= index < self.len()

Computes in O(1) time.

pub fn swap_remove_index(&mut self, index: usize) -> Option<T>[src]

Remove the key-value pair by index

Valid indices are 0 <= index < self.len()

Like Vec::swap_remove, the value is removed by swapping it with the last element of the set and popping it off. This perturbs the postion of what used to be the last element!

Computes in O(1) time (average).

pub fn shift_remove_index(&mut self, index: usize) -> Option<T>[src]

Remove the key-value pair by index

Valid indices are 0 <= index < self.len()

Like Vec::remove, the value is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

Computes in O(n) time (average).

impl<T, S> IndexSet<T, S> where
    T: Eq + Hash,
    S: BuildHasher
[src]

pub fn is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher
[src]

Returns true if self has no elements in common with other.

pub fn is_subset<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher
[src]

Returns true if all elements of self are contained in other.

pub fn is_superset<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher
[src]

Returns true if all elements of other are contained in self.

impl<T, S> IndexSet<T, S> where
    T: Hash + Eq + Sync,
    S: BuildHasher + Sync
[src]

Requires crate feature "rayon".

pub fn par_difference<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> ParDifference<'a, T, S, S2> where
    S2: BuildHasher + Sync
[src]

Return a parallel iterator over the values that are in self but not other.

While parallel iterators can process items in any order, their relative order in the self set is still preserved for operations like reduce and collect.

pub fn par_symmetric_difference<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> ParSymmetricDifference<'a, T, S, S2> where
    S2: BuildHasher + Sync
[src]

Return a parallel iterator over the values that are in self or other, but not in both.

While parallel iterators can process items in any order, their relative order in the sets is still preserved for operations like reduce and collect. Values from self are produced in their original order, followed by values from other in their original order.

pub fn par_intersection<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> ParIntersection<'a, T, S, S2> where
    S2: BuildHasher + Sync
[src]

Return a parallel iterator over the values that are in both self and other.

While parallel iterators can process items in any order, their relative order in the self set is still preserved for operations like reduce and collect.

pub fn par_union<'a, S2>(
    &'a self,
    other: &'a IndexSet<T, S2>
) -> ParUnion<'a, T, S, S2> where
    S2: BuildHasher + Sync
[src]

Return a parallel iterator over all values that are in self or other.

While parallel iterators can process items in any order, their relative order in the sets is still preserved for operations like reduce and collect. Values from self are produced in their original order, followed by values that are unique to other in their original order.

pub fn par_eq<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher + Sync
[src]

Returns true if self contains all of the same values as other, regardless of each set's indexed order, determined in parallel.

pub fn par_is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher + Sync
[src]

Returns true if self has no elements in common with other, determined in parallel.

pub fn par_is_superset<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher + Sync
[src]

Returns true if all elements of other are contained in self, determined in parallel.

pub fn par_is_subset<S2>(&self, other: &IndexSet<T, S2>) -> bool where
    S2: BuildHasher + Sync
[src]

Returns true if all elements of self are contained in other, determined in parallel.

impl<T, S> IndexSet<T, S> where
    T: Hash + Eq + Send,
    S: BuildHasher + Send
[src]

Requires crate feature "rayon".

pub fn par_sort(&mut self) where
    T: Ord
[src]

Sort the set’s values in parallel by their default ordering.

pub fn par_sort_by<F>(&mut self, cmp: F) where
    F: Fn(&T, &T) -> Ordering + Sync
[src]

Sort the set’s values in place and in parallel, using the comparison function compare.

pub fn par_sorted_by<F>(self, cmp: F) -> IntoParIter<T> where
    F: Fn(&T, &T) -> Ordering + Sync
[src]

Sort the values of the set in parallel and return a by value parallel iterator of the values with the result.

Trait Implementations

impl<T, S> Eq for IndexSet<T, S> where
    T: Eq + Hash,
    S: BuildHasher
[src]

impl<T, S> Extend<T> for IndexSet<T, S> where
    T: Hash + Eq,
    S: BuildHasher
[src]

impl<'a, T, S> Extend<&'a T> for IndexSet<T, S> where
    T: Hash + Eq + Copy + 'a,
    S: BuildHasher
[src]

impl<T, S> Default for IndexSet<T, S> where
    S: BuildHasher + Default
[src]

fn default() -> Self[src]

Return an empty IndexSet

impl<T: Clone, S: Clone> Clone for IndexSet<T, S>[src]

impl<T, S1, S2> PartialEq<IndexSet<T, S2>> for IndexSet<T, S1> where
    T: Hash + Eq,
    S1: BuildHasher,
    S2: BuildHasher
[src]

impl<'a, T, S> IntoIterator for &'a IndexSet<T, S> where
    T: Hash + Eq,
    S: BuildHasher
[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T, S> IntoIterator for IndexSet<T, S> where
    T: Hash + Eq,
    S: BuildHasher
[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, 'b, T, S1, S2> Sub<&'b IndexSet<T, S2>> for &'a IndexSet<T, S1> where
    T: Eq + Hash + Clone,
    S1: BuildHasher + Default,
    S2: BuildHasher
[src]

type Output = IndexSet<T, S1>

The resulting type after applying the - operator.

fn sub(self, other: &'b IndexSet<T, S2>) -> Self::Output[src]

Returns the set difference, cloned into a new set.

Values are collected in the same order that they appear in self.

impl<'a, 'b, T, S1, S2> BitAnd<&'b IndexSet<T, S2>> for &'a IndexSet<T, S1> where
    T: Eq + Hash + Clone,
    S1: BuildHasher + Default,
    S2: BuildHasher
[src]

type Output = IndexSet<T, S1>

The resulting type after applying the & operator.

fn bitand(self, other: &'b IndexSet<T, S2>) -> Self::Output[src]

Returns the set intersection, cloned into a new set.

Values are collected in the same order that they appear in self.

impl<'a, 'b, T, S1, S2> BitOr<&'b IndexSet<T, S2>> for &'a IndexSet<T, S1> where
    T: Eq + Hash + Clone,
    S1: BuildHasher + Default,
    S2: BuildHasher
[src]

type Output = IndexSet<T, S1>

The resulting type after applying the | operator.

fn bitor(self, other: &'b IndexSet<T, S2>) -> Self::Output[src]

Returns the set union, cloned into a new set.

Values from self are collected in their original order, followed by values that are unique to other in their original order.

impl<'a, 'b, T, S1, S2> BitXor<&'b IndexSet<T, S2>> for &'a IndexSet<T, S1> where
    T: Eq + Hash + Clone,
    S1: BuildHasher + Default,
    S2: BuildHasher
[src]

type Output = IndexSet<T, S1>

The resulting type after applying the ^ operator.

fn bitxor(self, other: &'b IndexSet<T, S2>) -> Self::Output[src]

Returns the set symmetric-difference, cloned into a new set.

Values from self are collected in their original order, followed by values from other in their original order.

impl<T, S> Debug for IndexSet<T, S> where
    T: Debug + Hash + Eq,
    S: BuildHasher
[src]

impl<T, S> FromIterator<T> for IndexSet<T, S> where
    T: Hash + Eq,
    S: BuildHasher + Default
[src]

impl<T, S> Serialize for IndexSet<T, S> where
    T: Serialize + Hash + Eq,
    S: BuildHasher
[src]

Requires crate feature "serde-1"

impl<'de, T, S, E> IntoDeserializer<'de, E> for IndexSet<T, S> where
    T: IntoDeserializer<'de, E> + Eq + Hash,
    S: BuildHasher,
    E: Error
[src]

type Deserializer = SeqDeserializer<Self::IntoIter, E>

The type of the deserializer being converted into.

impl<'de, T, S> Deserialize<'de> for IndexSet<T, S> where
    T: Deserialize<'de> + Eq + Hash,
    S: Default + BuildHasher
[src]

Requires crate feature "serde-1"

impl<T, S> IntoParallelIterator for IndexSet<T, S> where
    T: Hash + Eq + Send,
    S: BuildHasher
[src]

Requires crate feature "rayon".

type Item = T

The type of item that the parallel iterator will produce.

type Iter = IntoParIter<T>

The parallel iterator type that will be created.

impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S> where
    T: Hash + Eq + Sync,
    S: BuildHasher
[src]

Requires crate feature "rayon".

type Item = &'a T

The type of item that the parallel iterator will produce.

type Iter = ParIter<'a, T>

The parallel iterator type that will be created.

impl<T, S> ParallelExtend<T> for IndexSet<T, S> where
    T: Eq + Hash + Send,
    S: BuildHasher + Send
[src]

Requires crate feature "rayon".

impl<'a, T: 'a, S> ParallelExtend<&'a T> for IndexSet<T, S> where
    T: Copy + Eq + Hash + Send + Sync,
    S: BuildHasher + Send
[src]

Requires crate feature "rayon".

impl<T, S> FromParallelIterator<T> for IndexSet<T, S> where
    T: Eq + Hash + Send,
    S: BuildHasher + Default + Send
[src]

Requires crate feature "rayon".

Auto Trait Implementations

impl<T, S> Unpin for IndexSet<T, S> where
    S: Unpin,
    T: Unpin

impl<T, S> Sync for IndexSet<T, S> where
    S: Sync,
    T: Sync

impl<T, S> Send for IndexSet<T, S> where
    S: Send,
    T: Send

impl<T, S> UnwindSafe for IndexSet<T, S> where
    S: UnwindSafe,
    T: UnwindSafe

impl<T, S> RefUnwindSafe for IndexSet<T, S> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

impl<T> IntoParallelIterator for T where
    T: ParallelIterator
[src]

type Iter = T

The parallel iterator type that will be created.

type Item = <T as ParallelIterator>::Item

The type of item that the parallel iterator will produce.

impl<'data, I> IntoParallelRefIterator<'data> for I where
    I: 'data + ?Sized,
    &'data I: IntoParallelIterator
[src]

type Iter = <&'data I as IntoParallelIterator>::Iter

The type of the parallel iterator that will be returned.

type Item = <&'data I as IntoParallelIterator>::Item

The type of item that the parallel iterator will produce. This will typically be an &'data T reference type. Read more