pub struct SmallSet<A: Array>{ /* private fields */ }Expand description
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));Implementations§
Source§impl<A: Array> SmallSet<A>
impl<A: Array> SmallSet<A>
Sourcepub fn insert(&mut self, elem: A::Item) -> bool
pub 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.
Sourcepub fn remove(&mut self, elem: &A::Item) -> bool
pub 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.
Sourcepub fn contains(&self, elem: &A::Item) -> bool
pub fn contains(&self, elem: &A::Item) -> bool
Tests whether elem is present. Returns true if it is present, or
false if not.