pub struct SmallSet<T>(/* private fields */);
Expand description

An memory-efficient set with deterministic order, based on SmallMap.

Implementations§

source§

impl<T> SmallSet<T>

source

pub const fn new() -> Self

Creates an empty SmallSet.

source

pub fn with_capacity(n: usize) -> Self

Empty small set with preallocated capacity.

source

pub fn capacity(&self) -> usize

Current capacity of the set.

source

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

Iterate the element references.

source

pub fn iter_hashed(&self) -> IterHashed<'_, T>

Iterate the hashed element references.

source

pub fn iter_mut_unchecked(&mut self) -> IterMutUnchecked<'_, T>

Iterate the mutable element references.

This operation is memory safe, but otherwise no guarantees if keys are mutated inconsistently (hash or equality changes).

source

pub fn into_iter_hashed(self) -> IntoIterHashed<T>

Into hashed entries.

source

pub fn insert(&mut self, key: T) -> bool
where T: Hash + Eq,

Insert the element into the set.

Return true iff the element was inserted.

source

pub fn insert_unique_unchecked(&mut self, key: T)
where T: Hash,

Insert the element into the set without checking for a duplicate entry.

source

pub fn insert_hashed(&mut self, key: Hashed<T>) -> bool
where T: Eq,

Insert the element into the set.

Return true iff the element was inserted.

source

pub fn insert_hashed_unique_unchecked(&mut self, key: Hashed<T>)

Insert an entry into the set without checking for a duplicate key.

source

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

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_hashed<Q>(&self, value: Hashed<&Q>) -> Option<&T>
where Q: Equivalent<T> + ?Sized, T: Eq,

Query the set by a prehashed value.

source

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

Find an entry by an index.

source

pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>
where Q: Hash + Equivalent<T> + ?Sized, T: Eq,

Return item index, if it exists in the set

source

pub fn get_index_of_hashed<Q>(&self, value: Hashed<&Q>) -> Option<usize>
where Q: Equivalent<T> + ?Sized, T: Eq,

Find the index of the given hashed value.

source

pub fn get_index_of_hashed_by_value<Q>(&self, value: Hashed<Q>) -> Option<usize>
where Q: Equivalent<T>, T: Eq,

Find the index of the given hashed value.

This operations is similar to get_index_of_hashed, but it takes the key by value, instead of by reference which sometimes generates better code.

source

pub fn remove<Q>(&mut self, key: &Q) -> bool
where Q: ?Sized + Hash + Equivalent<T>, T: Eq,

Remove the element from the set if it is present.

Time complexity of this operation is O(N) where N is the number of entries in the set.

source

pub fn get_or_insert(&mut self, value: T) -> &T
where T: Hash + Eq,

Insert entry if it doesn’t exist.

Return the resulting entry in the map.

source

pub fn get_or_insert_owned<Q>(&mut self, value: &Q) -> &T
where Q: Hash + Equivalent<T> + ToOwned<Owned = T> + ?Sized, T: Eq,

Insert entry if it doesn’t exist.

Return the resulting entry in the map.

source

pub fn take<Q>(&mut self, key: &Q) -> Option<T>
where Q: ?Sized + Hash + Equivalent<T>, T: Eq,

Remove the element from the set if it is present,

and return the removed element.

source

pub fn pop(&mut self) -> Option<T>
where T: Eq,

Remove the last element from the set.

source

pub fn is_empty(&self) -> bool

Is the set empty?

source

pub fn len(&self) -> usize

Number of elements in the set.

source

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

Check if the set contains an element.

source

pub fn contains_hashed<Q>(&self, key: Hashed<&Q>) -> bool
where Q: Equivalent<T> + ?Sized, T: Eq,

Check if the set contains an element.

source

pub fn clear(&mut self)

Remove all elements from the set.

Retain the capacity.

source

pub fn first(&self) -> Option<&T>

Returns a reference to the first item.

source

pub fn last(&self) -> Option<&T>

Returns a reference to the last item.

source

pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T>
where T: Eq + Hash,

Iterator over elements of this set which are not in the other set.

source

pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T>
where T: Eq + Hash,

Iterator over union of two sets.

Iteration order is: elements of this set followed by elements in the other set not present in this set.

source

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

Sort entries.

source

pub fn eq_ordered(&self, other: &Self) -> bool
where T: PartialEq,

Equal if entries are equal in iteration order.

source

pub fn hash_ordered<H: Hasher>(&self, state: &mut H)
where T: Hash,

Hash entries in iteration order.

Note, entries are not hashed, but previously computed hashes are hashed instead.

source

pub fn reverse(&mut self)

Reverse the iteration order of the set.

Trait Implementations§

source§

impl<T: Allocative> Allocative for SmallSet<T>

source§

fn visit<'allocative_a, 'allocative_b: 'allocative_a>( &self, visitor: &'allocative_a mut Visitor<'allocative_b> )

source§

impl<T: Clone> Clone for SmallSet<T>

source§

fn clone(&self) -> SmallSet<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 SmallSet<T>

source§

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

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

impl<T> Default for SmallSet<T>

source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for SmallSet<T>
where T: Deserialize<'de> + Hash + Eq,

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<T> Extend<T> for SmallSet<T>
where T: Eq + Hash,

source§

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

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> From<SmallSet<T>> for OrderedSet<T>

source§

fn from(set: SmallSet<T>) -> OrderedSet<T>

Converts to this type from the input type.
source§

impl<T> From<SmallSet<T>> for SortedSet<T>
where T: Eq + Ord + Hash,

source§

fn from(inner: SmallSet<T>) -> SortedSet<T>

Converts to this type from the input type.
source§

impl<T> FromIterator<T> for SmallSet<T>
where T: Hash + Eq,

source§

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

Creates a value from an iterator. Read more
source§

impl<'a, T> IntoIterator for &'a SmallSet<T>

§

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?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for SmallSet<T>

§

type Item = T

The type of the elements being iterated over.
§

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> PartialEq for SmallSet<T>
where T: Eq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Serialize> Serialize for SmallSet<T>

source§

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

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

impl<T> Eq for SmallSet<T>
where T: Eq,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for SmallSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for SmallSet<T>
where T: Send,

§

impl<T> Sync for SmallSet<T>
where T: Sync,

§

impl<T> Unpin for SmallSet<T>
where T: Unpin,

§

impl<T> UnwindSafe for SmallSet<T>
where T: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Compare self to key and return true if they are equal.
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,

§

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>,

§

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>,

§

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>,