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

## Expand description

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
`IndexSet::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.

## §Complexity

Internally, `IndexSet<T, S>`

just holds an `IndexMap<T, (), S>`

. Thus the complexity
of the two are the same for most methods.

## §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'));
```

## Implementations§

source§### impl<T> IndexSet<T>

### impl<T> IndexSet<T>

source#### pub fn new() -> Self

Available on **crate feature **`std`

only.

#### pub fn new() -> Self

**crate feature**only.

`std`

Create a new set. (Does not allocate.)

source#### pub fn with_capacity(n: usize) -> Self

Available on **crate feature **`std`

only.

#### pub fn with_capacity(n: usize) -> Self

**crate feature**only.

`std`

Create a new set with capacity for `n`

elements.
(Does not allocate if `n`

is zero.)

Computes in **O(n)** time.

source§### impl<T, S> IndexSet<T, S>

### impl<T, S> IndexSet<T, S>

source#### pub fn with_capacity_and_hasher(n: usize, hash_builder: S) -> Self

#### pub fn with_capacity_and_hasher(n: usize, hash_builder: S) -> Self

Create a new set with capacity for `n`

elements.
(Does not allocate if `n`

is zero.)

Computes in **O(n)** time.

source#### pub const fn with_hasher(hash_builder: S) -> Self

#### pub const fn with_hasher(hash_builder: S) -> Self

Create a new set with `hash_builder`

.

This function is `const`

, so it
can be called in `static`

contexts.

source#### pub fn capacity(&self) -> usize

#### pub fn capacity(&self) -> usize

Return the number of elements the set can hold without reallocating.

This number is a lower bound; the set might be able to hold more, but is guaranteed to be able to hold at least this many.

Computes in **O(1)** time.

source#### pub fn is_empty(&self) -> bool

#### pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

Computes in **O(1)** time.

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

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

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

source#### pub fn clear(&mut self)

#### pub fn clear(&mut self)

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

Computes in **O(n)** time.

source#### pub fn truncate(&mut self, len: usize)

#### pub fn truncate(&mut self, len: usize)

Shortens the set, keeping the first `len`

elements and dropping the rest.

If `len`

is greater than the set’s current length, this has no effect.

source#### pub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,

#### pub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,

Clears the `IndexSet`

in the given index range, returning those values
as a drain iterator.

The range may be any type that implements `RangeBounds<usize>`

,
including all of the `std::ops::Range*`

types, or even a tuple pair of
`Bound`

start and end values. To drain the set entirely, use `RangeFull`

like `set.drain(..)`

.

This shifts down all entries following the drained range to fill the gap, and keeps the allocated memory for reuse.

* Panics* if the starting point is greater than the end point or if
the end point is greater than the length of the set.

source#### pub fn split_off(&mut self, at: usize) -> Selfwhere
S: Clone,

#### pub fn split_off(&mut self, at: usize) -> Selfwhere
S: Clone,

Splits the collection into two at the given index.

Returns a newly allocated set containing the elements in the range
`[at, len)`

. After the call, the original set will be left containing
the elements `[0, at)`

with its previous capacity unchanged.

* Panics* if

`at > len`

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

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

Reserve capacity for `additional`

more values.

Computes in **O(n)** time.

source#### pub fn reserve_exact(&mut self, additional: usize)

#### pub fn reserve_exact(&mut self, additional: usize)

Reserve capacity for `additional`

more values, without over-allocating.

Unlike `reserve`

, this does not deliberately over-allocate the entry capacity to avoid
frequent re-allocations. However, the underlying data structures may still have internal
capacity requirements, and the allocator itself may give more space than requested, so this
cannot be relied upon to be precisely minimal.

Computes in **O(n)** time.

source#### pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

#### pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Try to reserve capacity for `additional`

more values.

Computes in **O(n)** time.

source#### pub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>

#### pub fn try_reserve_exact( &mut self, additional: usize ) -> Result<(), TryReserveError>

Try to reserve capacity for `additional`

more values, without over-allocating.

Unlike `try_reserve`

, this does not deliberately over-allocate the entry capacity to avoid
frequent re-allocations. However, the underlying data structures may still have internal
capacity requirements, and the allocator itself may give more space than requested, so this
cannot be relied upon to be precisely minimal.

Computes in **O(n)** time.

source#### pub fn shrink_to_fit(&mut self)

#### pub fn shrink_to_fit(&mut self)

Shrink the capacity of the set as much as possible.

Computes in **O(n)** time.

source§### impl<T, S> IndexSet<T, S>

### impl<T, S> IndexSet<T, S>

source#### pub fn insert(&mut self, value: T) -> bool

#### pub fn insert(&mut self, value: T) -> bool

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

source#### pub fn insert_full(&mut self, value: T) -> (usize, bool)

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

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

source#### pub fn insert_sorted(&mut self, value: T) -> (usize, bool)where
T: Ord,

#### pub fn insert_sorted(&mut self, value: T) -> (usize, bool)where
T: Ord,

Insert the value into the set at its ordered position among sorted values.

This is equivalent to finding the position with
`binary_search`

, and if needed calling
`shift_insert`

for a new value.

If the sorted item is found in the set, it returns the index of that
existing item and `false`

, without any change. Otherwise, it inserts the
new item and returns its sorted index and `true`

.

If the existing items are **not** already sorted, then the insertion
index is unspecified (like `slice::binary_search`

), but the value
is moved to or inserted at that position regardless.

Computes in **O(n)** time (average). Instead of repeating calls to
`insert_sorted`

, it may be faster to call batched `insert`

or `extend`

and only call `sort`

or
`sort_unstable`

once.

source#### pub fn shift_insert(&mut self, index: usize, value: T) -> bool

#### pub fn shift_insert(&mut self, index: usize, value: T) -> bool

Insert the value into the set at the given index.

If an equivalent item already exists in the set, it returns
`false`

leaving the original value in the set, but moving it to
the new position in the set. Otherwise, it inserts the new
item at the given index and returns `true`

.

* Panics* if

`index`

is out of bounds.Computes in **O(n)** time (average).

source#### pub fn replace(&mut self, value: T) -> Option<T>

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

Adds a value to the set, replacing the existing value, if any, that is equal to the given one, without altering its insertion order. Returns the replaced value.

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

source#### pub fn replace_full(&mut self, value: T) -> (usize, Option<T>)

#### pub fn replace_full(&mut self, value: T) -> (usize, Option<T>)

Adds a value to the set, replacing the existing value, if any, that is equal to the given one, without altering its insertion order. Returns the index of the item and its replaced value.

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

source#### pub fn difference<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> Difference<'a, T, S2> ⓘwhere
S2: BuildHasher,

#### pub fn difference<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> Difference<'a, T, S2> ⓘwhere
S2: BuildHasher,

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`

.

source#### pub fn symmetric_difference<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> SymmetricDifference<'a, T, S, S2> ⓘwhere
S2: BuildHasher,

#### pub fn symmetric_difference<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> SymmetricDifference<'a, T, S, S2> ⓘwhere
S2: BuildHasher,

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.

source#### pub fn intersection<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> Intersection<'a, T, S2> ⓘwhere
S2: BuildHasher,

#### pub fn intersection<'a, S2>(
&'a self,
other: &'a IndexSet<T, S2>
) -> Intersection<'a, T, S2> ⓘwhere
S2: BuildHasher,

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`

.

source#### pub fn union<'a, S2>(&'a self, other: &'a IndexSet<T, S2>) -> Union<'a, T, S> ⓘwhere
S2: BuildHasher,

#### pub fn union<'a, S2>(&'a self, other: &'a IndexSet<T, S2>) -> Union<'a, T, S> ⓘwhere
S2: BuildHasher,

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.

source#### pub fn splice<R, I>(
&mut self,
range: R,
replace_with: I
) -> Splice<'_, I::IntoIter, T, S> ⓘ

#### pub fn splice<R, I>( &mut self, range: R, replace_with: I ) -> Splice<'_, I::IntoIter, T, S> ⓘ

Creates a splicing iterator that replaces the specified range in the set
with the given `replace_with`

iterator and yields the removed items.
`replace_with`

does not need to be the same length as `range`

.

The `range`

is removed even if the iterator is not consumed until the
end. It is unspecified how many elements are removed from the set if the
`Splice`

value is leaked.

The input iterator `replace_with`

is only consumed when the `Splice`

value is dropped. If a value from the iterator matches an existing entry
in the set (outside of `range`

), then the original will be unchanged.
Otherwise, the new value will be inserted in the replaced `range`

.

* Panics* if the starting point is greater than the end point or if
the end point is greater than the length of the set.

##### §Examples

```
use indexmap::IndexSet;
let mut set = IndexSet::from([0, 1, 2, 3, 4]);
let new = [5, 4, 3, 2, 1];
let removed: Vec<_> = set.splice(2..4, new).collect();
// 1 and 4 kept their positions, while 5, 3, and 2 were newly inserted.
assert!(set.into_iter().eq([0, 1, 5, 3, 2, 4]));
assert_eq!(removed, &[2, 3]);
```

source§### impl<T, S> IndexSet<T, S>where
S: BuildHasher,

### impl<T, S> IndexSet<T, S>where
S: BuildHasher,

source#### pub fn contains<Q>(&self, value: &Q) -> bool

#### pub fn contains<Q>(&self, value: &Q) -> bool

Return `true`

if an equivalent to `value`

exists in the set.

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

source#### pub fn get<Q>(&self, value: &Q) -> Option<&T>

#### pub fn get<Q>(&self, value: &Q) -> Option<&T>

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

.

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

source#### pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>

#### pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>

Return item index, if it exists in the set

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

source#### pub fn remove<Q>(&mut self, value: &Q) -> bool

👎Deprecated: `remove`

disrupts the set order – use `swap_remove`

or `shift_remove`

for explicit behavior.

#### pub fn remove<Q>(&mut self, value: &Q) -> bool

`remove`

disrupts the set order – use `swap_remove`

or `shift_remove`

for explicit behavior.Remove the value from the set, and return `true`

if it was present.

**NOTE:** This is equivalent to `.swap_remove(value)`

, replacing this
value’s position with the last element, and it is deprecated in favor of calling that
explicitly. If you need to preserve the relative order of the values in the set, use
`.shift_remove(value)`

instead.

source#### pub fn swap_remove<Q>(&mut self, value: &Q) -> bool

#### pub fn swap_remove<Q>(&mut self, value: &Q) -> bool

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 position of what used to be the last element!**

Return `false`

if `value`

was not in the set.

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

source#### pub fn shift_remove<Q>(&mut self, value: &Q) -> bool

#### pub fn shift_remove<Q>(&mut self, value: &Q) -> bool

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

source#### pub fn take<Q>(&mut self, value: &Q) -> Option<T>

👎Deprecated: `take`

disrupts the set order – use `swap_take`

or `shift_take`

for explicit behavior.

#### pub fn take<Q>(&mut self, value: &Q) -> Option<T>

`take`

disrupts the set order – use `swap_take`

or `shift_take`

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

**NOTE:** This is equivalent to `.swap_take(value)`

, replacing this
value’s position with the last element, and it is deprecated in favor of calling that
explicitly. If you need to preserve the relative order of the values in the set, use
`.shift_take(value)`

instead.

source#### pub fn swap_take<Q>(&mut self, value: &Q) -> Option<T>

#### pub fn swap_take<Q>(&mut self, value: &Q) -> Option<T>

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 position of what used to be the last element!**

Return `None`

if `value`

was not in the set.

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

source#### pub fn shift_take<Q>(&mut self, value: &Q) -> Option<T>

#### pub fn shift_take<Q>(&mut self, value: &Q) -> Option<T>

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

source#### pub fn swap_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>

#### pub fn swap_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>

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 position of what used to be the last element!**

Return `None`

if `value`

was not in the set.

source#### pub fn shift_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>

#### pub fn shift_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>

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.

source§### impl<T, S> IndexSet<T, S>

### impl<T, S> IndexSet<T, S>

source#### pub fn pop(&mut self) -> Option<T>

#### pub fn pop(&mut self) -> Option<T>

Remove the last value

This preserves the order of the remaining elements.

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

source#### pub fn retain<F>(&mut self, keep: F)

#### pub fn retain<F>(&mut self, keep: F)

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

source#### pub fn sort(&mut self)where
T: Ord,

#### pub fn sort(&mut self)where
T: Ord,

Sort the set’s values by their default ordering.

This is a stable sort – but equivalent values should not normally coexist in
a set at all, so `sort_unstable`

is preferred
because it is generally faster and doesn’t allocate auxiliary memory.

See `sort_by`

for details.

source#### pub fn sort_by<F>(&mut self, cmp: F)

#### pub fn sort_by<F>(&mut self, cmp: F)

Sort the set’s values in place using the comparison function `cmp`

.

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

source#### pub fn sorted_by<F>(self, cmp: F) -> IntoIter<T> ⓘ

#### pub fn sorted_by<F>(self, cmp: F) -> IntoIter<T> ⓘ

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

The sort is stable.

source#### pub fn sort_unstable(&mut self)where
T: Ord,

#### pub fn sort_unstable(&mut self)where
T: Ord,

Sort the set’s values by their default ordering.

See `sort_unstable_by`

for details.

source#### pub fn sort_unstable_by<F>(&mut self, cmp: F)

#### pub fn sort_unstable_by<F>(&mut self, cmp: F)

Sort the set’s values in place using the comparison function `cmp`

.

Computes in **O(n log n)** time. The sort is unstable.

source#### pub fn sorted_unstable_by<F>(self, cmp: F) -> IntoIter<T> ⓘ

#### pub fn sorted_unstable_by<F>(self, cmp: F) -> IntoIter<T> ⓘ

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

source#### pub fn sort_by_cached_key<K, F>(&mut self, sort_key: F)

#### pub fn sort_by_cached_key<K, F>(&mut self, sort_key: F)

Sort the set’s values in place using a key extraction function.

During sorting, the function is called at most once per entry, by using temporary storage
to remember the results of its evaluation. The order of calls to the function is
unspecified and may change between versions of `indexmap`

or the standard library.

Computes in **O(m n + n log n + c)** time () and **O(n)** space, where the function is
**O(m)**, *n* is the length of the map, and *c* the capacity. The sort is stable.

source#### pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,

#### pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,

Search over a sorted set for a value.

Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See `slice::binary_search`

for more details.

Computes in **O(log(n))** time, which is notably less scalable than looking the value up
using `get_index_of`

, but this can also position missing values.

source#### pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>

#### pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>

Search over a sorted set with a comparator function.

Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See `slice::binary_search_by`

for more details.

Computes in **O(log(n))** time.

source#### pub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F
) -> Result<usize, usize>

#### pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F ) -> Result<usize, usize>

Search over a sorted set with an extraction function.

Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See `slice::binary_search_by_key`

for more details.

Computes in **O(log(n))** time.

source#### pub fn partition_point<P>(&self, pred: P) -> usize

#### pub fn partition_point<P>(&self, pred: P) -> usize

Returns the index of the partition point of a sorted set according to the given predicate (the index of the first element of the second partition).

See `slice::partition_point`

for more details.

Computes in **O(log(n))** time.

source#### pub fn reverse(&mut self)

#### pub fn reverse(&mut self)

Reverses the order of the set’s values in place.

Computes in **O(n)** time and **O(1)** space.

source#### pub fn as_slice(&self) -> &Slice<T>

#### pub fn as_slice(&self) -> &Slice<T>

Returns a slice of all the values in the set.

Computes in **O(1)** time.

source#### pub fn into_boxed_slice(self) -> Box<Slice<T>>

#### pub fn into_boxed_slice(self) -> Box<Slice<T>>

Converts into a boxed slice of all the values in the set.

Note that this will drop the inner hash table and any excess capacity.

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

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

Get a value by index

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

Computes in **O(1)** time.

source#### pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Slice<T>>

#### pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Slice<T>>

Returns a slice of values in the given range of indices.

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

Computes in **O(1)** time.

source#### pub fn swap_remove_index(&mut self, index: usize) -> Option<T>

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

Remove the value by index

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

`Vec::swap_remove`

, the value is removed by swapping it with the
last element of the set and popping it off. **This perturbs
the position of what used to be the last element!**

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

source#### pub fn shift_remove_index(&mut self, index: usize) -> Option<T>

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

Remove the value by index

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

`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).

source#### pub fn move_index(&mut self, from: usize, to: usize)

#### pub fn move_index(&mut self, from: usize, to: usize)

Moves the position of a value from one index to another by shifting all other values in-between.

- If
`from < to`

, the other values will shift down while the targeted value moves up. - If
`from > to`

, the other values will shift up while the targeted value moves down.

* Panics* if

`from`

or `to`

are out of bounds.Computes in **O(n)** time (average).

source#### pub fn swap_indices(&mut self, a: usize, b: usize)

#### pub fn swap_indices(&mut self, a: usize, b: usize)

Swaps the position of two values in the set.

* Panics* if

`a`

or `b`

are out of bounds.Computes in **O(1)** time (average).

source§### impl<T, S> IndexSet<T, S>

### impl<T, S> IndexSet<T, S>

source#### pub fn is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

#### pub fn is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

Returns `true`

if `self`

has no elements in common with `other`

.

source#### pub fn is_subset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

#### pub fn is_subset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

Returns `true`

if all elements of `self`

are contained in `other`

.

source#### pub fn is_superset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

#### pub fn is_superset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher,

Returns `true`

if all elements of `other`

are contained in `self`

.

source§### impl<T, S> IndexSet<T, S>

### impl<T, S> IndexSet<T, S>

Parallel iterator methods and other parallel methods.

The following methods **require crate feature "rayon"**.

See also the `IntoParallelIterator`

implementations.

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

Available on **crate feature **`rayon`

only.

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

**crate feature**only.

`rayon`

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`

.

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

Available on **crate feature **`rayon`

only.

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

**crate feature**only.

`rayon`

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.

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

Available on **crate feature **`rayon`

only.

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

**crate feature**only.

`rayon`

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`

.

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

Available on **crate feature **`rayon`

only.

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

**crate feature**only.

`rayon`

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.

source#### pub fn par_eq<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

Available on **crate feature **`rayon`

only.

#### pub fn par_eq<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

**crate feature**only.

`rayon`

Returns `true`

if `self`

contains all of the same values as `other`

,
regardless of each set’s indexed order, determined in parallel.

source#### pub fn par_is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

Available on **crate feature **`rayon`

only.

#### pub fn par_is_disjoint<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

**crate feature**only.

`rayon`

Returns `true`

if `self`

has no elements in common with `other`

,
determined in parallel.

source#### pub fn par_is_superset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

Available on **crate feature **`rayon`

only.

#### pub fn par_is_superset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

**crate feature**only.

`rayon`

Returns `true`

if all elements of `other`

are contained in `self`

,
determined in parallel.

source#### pub fn par_is_subset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

Available on **crate feature **`rayon`

only.

#### pub fn par_is_subset<S2>(&self, other: &IndexSet<T, S2>) -> boolwhere
S2: BuildHasher + Sync,

**crate feature**only.

`rayon`

Returns `true`

if all elements of `self`

are contained in `other`

,
determined in parallel.

source§### impl<T, S> IndexSet<T, S>where
T: Send,

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

Parallel sorting methods.

The following methods **require crate feature "rayon"**.

source#### pub fn par_sort(&mut self)where
T: Ord,

Available on **crate feature **`rayon`

only.

#### pub fn par_sort(&mut self)where
T: Ord,

**crate feature**only.

`rayon`

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

source#### pub fn par_sort_by<F>(&mut self, cmp: F)

Available on **crate feature **`rayon`

only.

#### pub fn par_sort_by<F>(&mut self, cmp: F)

**crate feature**only.

`rayon`

Sort the set’s values in place and in parallel, using the comparison function `cmp`

.

source#### pub fn par_sorted_by<F>(self, cmp: F) -> IntoParIter<T>

Available on **crate feature **`rayon`

only.

#### pub fn par_sorted_by<F>(self, cmp: F) -> IntoParIter<T>

**crate feature**only.

`rayon`

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

source#### pub fn par_sort_unstable(&mut self)where
T: Ord,

Available on **crate feature **`rayon`

only.

#### pub fn par_sort_unstable(&mut self)where
T: Ord,

**crate feature**only.

`rayon`

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

source#### pub fn par_sort_unstable_by<F>(&mut self, cmp: F)

Available on **crate feature **`rayon`

only.

#### pub fn par_sort_unstable_by<F>(&mut self, cmp: F)

**crate feature**only.

`rayon`

Sort the set’s values in place and in parallel, using the comparison function `cmp`

.

source#### pub fn par_sorted_unstable_by<F>(self, cmp: F) -> IntoParIter<T>

Available on **crate feature **`rayon`

only.

#### pub fn par_sorted_unstable_by<F>(self, cmp: F) -> IntoParIter<T>

**crate feature**only.

`rayon`

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

## Trait Implementations§

source§### impl<'a, T, S> Arbitrary<'a> for IndexSet<T, S>

Available on **crate feature **`arbitrary`

only.

### impl<'a, T, S> Arbitrary<'a> for IndexSet<T, S>

**crate feature**only.

`arbitrary`

source§#### fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

#### fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

`Self`

from the given unstructured data. Read moresource§#### fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>

#### fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>

`Self`

from the entirety of the given
unstructured data. Read moresource§### impl<T, S1, S2> BitOr<&IndexSet<T, S2>> for &IndexSet<T, S1>

### impl<T, S1, S2> BitOr<&IndexSet<T, S2>> for &IndexSet<T, S1>

source§### impl<T, S1, S2> BitXor<&IndexSet<T, S2>> for &IndexSet<T, S1>

### impl<T, S1, S2> BitXor<&IndexSet<T, S2>> for &IndexSet<T, S1>

source§### impl<T, S> BorshDeserialize for IndexSet<T, S>

Available on **crate feature **`borsh`

only.

### impl<T, S> BorshDeserialize for IndexSet<T, S>

**crate feature**only.

`borsh`

#### fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>

source§#### fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

#### fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

source§#### fn try_from_slice(v: &[u8]) -> Result<Self, Error>

#### fn try_from_slice(v: &[u8]) -> Result<Self, Error>

#### fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,

source§### impl<T, S> BorshSerialize for IndexSet<T, S>where
T: BorshSerialize,

Available on **crate feature **`borsh`

only.

### impl<T, S> BorshSerialize for IndexSet<T, S>where
T: BorshSerialize,

**crate feature**only.

`borsh`

source§### impl<'de, T, S> Deserialize<'de> for IndexSet<T, S>

Available on **crate feature **`serde`

only.

### impl<'de, T, S> Deserialize<'de> for IndexSet<T, S>

**crate feature**only.

`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, S> Extend<&'a T> for IndexSet<T, S>

### impl<'a, T, S> Extend<&'a T> for IndexSet<T, S>

source§#### fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iterable: I)

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

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, S> Extend<T> for IndexSet<T, S>

### impl<T, S> Extend<T> for IndexSet<T, S>

source§#### fn extend<I: IntoIterator<Item = T>>(&mut self, iterable: I)

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

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, const N: usize> From<[T; N]> for IndexSet<T, RandomState>

Available on **crate feature **`std`

only.

### impl<T, const N: usize> From<[T; N]> for IndexSet<T, RandomState>

**crate feature**only.

`std`

source§### impl<T, S> FromIterator<T> for IndexSet<T, S>

### impl<T, S> FromIterator<T> for IndexSet<T, S>

source§#### fn from_iter<I: IntoIterator<Item = T>>(iterable: I) -> Self

#### fn from_iter<I: IntoIterator<Item = T>>(iterable: I) -> Self

source§### impl<T, S> FromParallelIterator<T> for IndexSet<T, S>

Available on **crate feature **`rayon`

only.

### impl<T, S> FromParallelIterator<T> for IndexSet<T, S>

**crate feature**only.

`rayon`

source§#### fn from_par_iter<I>(iter: I) -> Selfwhere
I: IntoParallelIterator<Item = T>,

#### fn from_par_iter<I>(iter: I) -> Selfwhere
I: IntoParallelIterator<Item = T>,

`par_iter`

. Read moresource§### impl<T, S> Index<usize> for IndexSet<T, S>

### impl<T, S> Index<usize> for IndexSet<T, S>

Access `IndexSet`

values at indexed positions.

#### §Examples

```
use indexmap::IndexSet;
let mut set = IndexSet::new();
for word in "Lorem ipsum dolor sit amet".split_whitespace() {
set.insert(word.to_string());
}
assert_eq!(set[0], "Lorem");
assert_eq!(set[1], "ipsum");
set.reverse();
assert_eq!(set[0], "amet");
assert_eq!(set[1], "sit");
set.sort();
assert_eq!(set[0], "Lorem");
assert_eq!(set[1], "amet");
```

```
use indexmap::IndexSet;
let mut set = IndexSet::new();
set.insert("foo");
println!("{:?}", set[10]); // panics!
```

source§### impl<'de, T, S, E> IntoDeserializer<'de, E> for IndexSet<T, S>

Available on **crate feature **`serde`

only.

### impl<'de, T, S, E> IntoDeserializer<'de, E> for IndexSet<T, S>

**crate feature**only.

`serde`

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

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

source§#### fn into_deserializer(self) -> Self::Deserializer

#### fn into_deserializer(self) -> Self::Deserializer

source§### impl<'a, T, S> IntoIterator for &'a IndexSet<T, S>

### impl<'a, T, S> IntoIterator for &'a IndexSet<T, S>

source§### impl<T, S> IntoIterator for IndexSet<T, S>

### impl<T, S> IntoIterator for IndexSet<T, S>

source§### impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>where
T: Sync,

Available on **crate feature **`rayon`

only.

### impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>where
T: Sync,

**crate feature**only.

`rayon`

source§### impl<T, S> IntoParallelIterator for IndexSet<T, S>where
T: Send,

Available on **crate feature **`rayon`

only.

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

**crate feature**only.

`rayon`

§#### type Iter = IntoParIter<T>

#### type Iter = IntoParIter<T>

source§#### fn into_par_iter(self) -> Self::Iter

#### fn into_par_iter(self) -> Self::Iter

`self`

into a parallel iterator. Read moresource§### impl<'a, T, S> ParallelDrainRange for &'a mut IndexSet<T, S>where
T: Send,

Available on **crate feature **`rayon`

only.

### impl<'a, T, S> ParallelDrainRange for &'a mut IndexSet<T, S>where
T: Send,

**crate feature**only.

`rayon`

source§### impl<'a, T, S> ParallelExtend<&'a T> for IndexSet<T, S>

Available on **crate feature **`rayon`

only.

### impl<'a, T, S> ParallelExtend<&'a T> for IndexSet<T, S>

**crate feature**only.

`rayon`

source§#### fn par_extend<I>(&mut self, iter: I)where
I: IntoParallelIterator<Item = &'a T>,

#### fn par_extend<I>(&mut self, iter: I)where
I: IntoParallelIterator<Item = &'a T>,

`par_iter`

. Read moresource§### impl<T, S> ParallelExtend<T> for IndexSet<T, S>

Available on **crate feature **`rayon`

only.

### impl<T, S> ParallelExtend<T> for IndexSet<T, S>

**crate feature**only.

`rayon`

source§#### fn par_extend<I>(&mut self, iter: I)where
I: IntoParallelIterator<Item = T>,

#### fn par_extend<I>(&mut self, iter: I)where
I: IntoParallelIterator<Item = T>,

`par_iter`

. Read moresource§### impl<T, S1, S2> PartialEq<IndexSet<T, S2>> for IndexSet<T, S1>

### impl<T, S1, S2> PartialEq<IndexSet<T, S2>> for IndexSet<T, S1>

source§### impl<T, S> Serialize for IndexSet<T, S>where
T: Serialize,

Available on **crate feature **`serde`

only.

### impl<T, S> Serialize for IndexSet<T, S>where
T: Serialize,

**crate feature**only.

`serde`

### impl<T, S> Eq for IndexSet<T, S>

## Auto Trait Implementations§

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

### impl<T, S> Send for IndexSet<T, S>

### impl<T, S> Sync for IndexSet<T, S>

### impl<T, S> Unpin for IndexSet<T, S>

### impl<T, S> UnwindSafe for IndexSet<T, S>where
S: UnwindSafe,
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<Q, K> Equivalent<K> for Q

### impl<Q, K> Equivalent<K> for Q

source§### impl<Q, K> Equivalent<K> for Q

### impl<Q, K> Equivalent<K> for Q

source§#### fn equivalent(&self, key: &K) -> bool

#### fn equivalent(&self, key: &K) -> bool

`key`

and return `true`

if they are equal.source§### impl<'data, I> IntoParallelRefIterator<'data> for I

### impl<'data, I> IntoParallelRefIterator<'data> for I

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

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

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

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

`&'data T`

reference type.