Struct smolset::SmolSet [−][src]
Expand description
A SmolSet
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 SmolSet
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 smolset::SmolSet;
// `s` and its elements will be completely stack-allocated in this example.
let mut s: SmolSet<[u32; 4]> = SmolSet::new();
s.insert(1);
s.insert(2);
s.insert(3);
assert_eq!(s.len(), 3);
assert!(s.contains(&1));
TODO: Add the ability to switch modes explicitly.
Implementations
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.
Removes elem
from the set. Returns true
if the element was removed,
or false
if it was not found.
Tests whether elem
is present. Returns true
if it is present, or
false
if not.
pub fn iter(&self) -> SmolSetIter<'_, A>ⓘNotable traits for SmolSetIter<'a, A>impl<'a, A: Array> Iterator for SmolSetIter<'a, A> where
A::Item: PartialEq + Eq + Hash + 'a, type Item = &'a A::Item;
pub fn iter(&self) -> SmolSetIter<'_, A>ⓘNotable traits for SmolSetIter<'a, A>impl<'a, A: Array> Iterator for SmolSetIter<'a, A> where
A::Item: PartialEq + Eq + Hash + 'a, type Item = &'a A::Item;
impl<'a, A: Array> Iterator for SmolSetIter<'a, A> where
A::Item: PartialEq + Eq + Hash + 'a, type Item = &'a A::Item;
Returns an iterator over the set elements. Elements will be returned in an arbitrary (unsorted) order.
If the given elem
exists in the set, returns the reference to the value inside the set.
Where they are equal (in the case where the set is in stack mode) or they hash equally (if the set is in heap mode).
If the given elem
exists in the set, returns the value inside the set where they are either equal or hash equally.
Then, remove that value from the set.
Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.
pub fn drain(&mut self) -> SmallDrain<A::Item>ⓘNotable traits for SmallDrain<T>impl<T> Iterator for SmallDrain<T> type Item = T;
pub fn drain(&mut self) -> SmallDrain<A::Item>ⓘNotable traits for SmallDrain<T>impl<T> Iterator for SmallDrain<T> type Item = T;
impl<T> Iterator for SmallDrain<T> type Item = T;
Empties the set and returns an iterator over it.
Removes all elements in the set that does not satisfy the given predicate f
.
pub fn intersection<'a>(
&'a self,
other: &'a Self
) -> SmallIntersection<'a, A::Item>ⓘNotable traits for SmallIntersection<'a, T>impl<'a, T> Iterator for SmallIntersection<'a, T> type Item = &'a T;
pub fn intersection<'a>(
&'a self,
other: &'a Self
) -> SmallIntersection<'a, A::Item>ⓘNotable traits for SmallIntersection<'a, T>impl<'a, T> Iterator for SmallIntersection<'a, T> type Item = &'a T;
impl<'a, T> Iterator for SmallIntersection<'a, T> type Item = &'a T;
Returns an iterator over the intersection of the 2 sets.
pub fn union<'a>(&'a self, other: &'a Self) -> SmallUnion<'a, A::Item>ⓘNotable traits for SmallUnion<'a, T>impl<'a, T> Iterator for SmallUnion<'a, T> type Item = &'a T;
pub fn union<'a>(&'a self, other: &'a Self) -> SmallUnion<'a, A::Item>ⓘNotable traits for SmallUnion<'a, T>impl<'a, T> Iterator for SmallUnion<'a, T> type Item = &'a T;
impl<'a, T> Iterator for SmallUnion<'a, T> type Item = &'a T;
Returns an iterator over the union of the 2 sets.
pub fn difference<'a>(&'a self, other: &'a Self) -> SmallDifference<'a, A::Item>ⓘNotable traits for SmallDifference<'a, T>impl<'a, T> Iterator for SmallDifference<'a, T> type Item = &'a T;
pub fn difference<'a>(&'a self, other: &'a Self) -> SmallDifference<'a, A::Item>ⓘNotable traits for SmallDifference<'a, T>impl<'a, T> Iterator for SmallDifference<'a, T> type Item = &'a T;
impl<'a, T> Iterator for SmallDifference<'a, T> type Item = &'a T;
Returns an iterator over the difference of the 2 sets.
pub fn symmetric_difference<'a>(
&'a self,
other: &'a Self
) -> SmallSymmetricDifference<'a, A::Item>ⓘNotable traits for SmallSymmetricDifference<'a, T>impl<'a, T> Iterator for SmallSymmetricDifference<'a, T> type Item = &'a T;
pub fn symmetric_difference<'a>(
&'a self,
other: &'a Self
) -> SmallSymmetricDifference<'a, A::Item>ⓘNotable traits for SmallSymmetricDifference<'a, T>impl<'a, T> Iterator for SmallSymmetricDifference<'a, T> type Item = &'a T;
impl<'a, T> Iterator for SmallSymmetricDifference<'a, T> type Item = &'a T;
Returns an iterator over the symmetric difference of the 2 sets.
Trait Implementations
Creates a value from an iterator. Read more
Implement into iterator for the SmolSet
Implement into iterator for borrowed SmolSet
Auto Trait Implementations
impl<A> RefUnwindSafe for SmolSet<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> UnwindSafe for SmolSet<A> where
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe + UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more