Struct smallset::SmallSet
[−]
[src]
pub struct SmallSet<A: Array> where A::Item: PartialEq + Eq {
// some 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]
fn new() -> SmallSet<A>
Creates a new, empty SmallSet.
fn insert(&mut self, elem: A::Item) -> bool
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.
fn remove(&mut self, elem: &A::Item) -> bool
Removes elem from the set. Returns true if the element was removed,
or false if it was not found.
fn contains(&self, elem: &A::Item) -> bool
Tests whether elem is present. Returns true if it is present, or
false if not.
fn iter(&self) -> Iter<A::Item>
Returns an iterator over the set elements. Elements will be returned in an arbitrary (unsorted) order.
fn len(&self) -> usize
Returns the current length of the set.
fn clear(&mut self)
Clears the set.