[][src]Struct smallset::SmallSet

pub struct SmallSet<A: Array> where
    A::Item: PartialEq + Eq
{ /* fields omitted */ }

A SmallSet is an unordered set of elements. It is designed to work best for very small sets (no more than ten or so elements). In order to support small sets very efficiently, it stores elements in a simple unordered array. When the set is smaller than the size of the array A, all elements are stored inline, without heap allocation. This is accomplished by using a smallvec::SmallVec.

The insert, remove, and query methods on SmallSet have O(n) time complexity in the current set size: they perform a linear scan to determine if the element in question is present. This is inefficient for large sets, but fast and cache-friendly for small sets.

Example usage:

use smallset::SmallSet;

// `s` and its elements will be completely stack-allocated in this example.
let mut s: SmallSet<[u32; 4]> = SmallSet::new();
s.insert(1);
s.insert(2);
s.insert(3);
assert!(s.len() == 3);
assert!(s.contains(&1));

Methods

impl<A: Array> SmallSet<A> where
    A::Item: PartialEq + Eq
[src]

pub fn new() -> SmallSet<A>[src]

Creates a new, empty SmallSet.

pub fn insert(&mut self, elem: A::Item) -> bool[src]

Inserts elem into the set if not yet present. Returns true if the set did not have this element present, or false if it already had this element present.

pub fn remove(&mut self, elem: &A::Item) -> bool[src]

Removes elem from the set. Returns true if the element was removed, or false if it was not found.

pub fn contains(&self, elem: &A::Item) -> bool[src]

Tests whether elem is present. Returns true if it is present, or false if not.

pub fn iter(&self) -> Iter<A::Item>[src]

Returns an iterator over the set elements. Elements will be returned in an arbitrary (unsorted) order.

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

Returns the current length of the set.

pub fn clear(&mut self)[src]

Clears the set.

Trait Implementations

impl<A: Array> Clone for SmallSet<A> where
    A::Item: PartialEq + Eq + Clone
[src]

impl<A: Array> Debug for SmallSet<A> where
    A::Item: PartialEq + Eq + Debug
[src]

impl<A: Array> FromIterator<<A as Array>::Item> for SmallSet<A> where
    A::Item: PartialEq + Eq
[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for SmallSet<A> where
    A: RefUnwindSafe,
    <A as Array>::Item: RefUnwindSafe

impl<A> Send for SmallSet<A> where
    <A as Array>::Item: Send

impl<A> Sync for SmallSet<A> where
    A: Sync

impl<A> Unpin for SmallSet<A> where
    A: Unpin

impl<A> UnwindSafe for SmallSet<A> where
    A: UnwindSafe,
    <A as Array>::Item: RefUnwindSafe

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.