Skip to main content

SmallSet

Struct SmallSet 

Source
pub struct SmallSet<T, const N: usize>(/* private fields */);
Expand description

A hash set, with a fast non-cryptographic hasher and deterministic iteration order, optimized for the common case of very few elements.

Up to N entries are stored inline, in a flat, linearly-scanned array, with no heap allocation and no hashing. Once an insert grows the set past N entries, it transparently and permanently promotes itself to an ISet

Implementations§

Source§

impl<T, const N: usize> SmallSet<T, N>

Source

pub fn new() -> SmallSet<T, N>

Creates an empty SmallSet. Does not allocate until it grows past N elements.

Source

pub fn is_inline(&self) -> bool

Returns true if this set has not (yet) grown past N elements, i.e., is still using inline, non-heap-allocated storage.

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 clear(&mut self)

Clears the set, removing all values. A previously promoted set stays promoted; see the SmallMap documentation.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all values v such that f(&v) returns false.

Source

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

Returns an iterator over the set’s elements.

Source§

impl<T, const N: usize> SmallSet<T, N>
where T: Hash + Eq,

Source

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

Adds a value to the set.

If the set did not have this value present, true is returned. If the set did have this value present, false is returned.

Source

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

Returns true if the set contains a value.

Source

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

Returns a reference to the value in the set, if any, that is equal to the given value.

Source

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

Removes a value from the set. Returns whether the value was present.

Trait Implementations§

Source§

impl<T, const N: usize> Clone for SmallSet<T, N>
where T: Clone,

Source§

fn clone(&self) -> SmallSet<T, N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize> Debug for SmallSet<T, N>
where T: Debug,

Source§

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

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

impl<T, const N: usize> Default for SmallSet<T, N>

Source§

fn default() -> SmallSet<T, N>

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

impl<T, const N: usize> Eq for SmallSet<T, N>
where T: Hash + Eq,

Source§

impl<T, const N: usize> Extend<T> for SmallSet<T, N>
where T: Hash + Eq,

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

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T, const N: usize> IntoIterator for SmallSet<T, N>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = SetIntoIter<T, N>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <SmallSet<T, N> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, const N: usize> IntoIterator for &'a SmallSet<T, N>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = SetIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a SmallSet<T, N> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, const N: usize> PartialEq for SmallSet<T, N>
where T: Hash + Eq,

Source§

fn eq(&self, other: &SmallSet<T, N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for SmallSet<T, N>
where SetRepr<T, N>: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for SmallSet<T, N>
where SetRepr<T, N>: RefUnwindSafe,

§

impl<T, const N: usize> Send for SmallSet<T, N>
where SetRepr<T, N>: Send,

§

impl<T, const N: usize> Sync for SmallSet<T, N>
where SetRepr<T, N>: Sync,

§

impl<T, const N: usize> Unpin for SmallSet<T, N>
where SetRepr<T, N>: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for SmallSet<T, N>
where SetRepr<T, N>: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for SmallSet<T, N>
where SetRepr<T, N>: 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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.