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
impl<A: Array> SmolSet<A> where
A::Item: PartialEq + Eq + Hash, [src]
impl<A: Array> SmolSet<A> where
A::Item: PartialEq + Eq + Hash, [src]pub fn mode(&self) -> SetMode[src]
pub fn insert(&mut self, elem: A::Item) -> bool[src]
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]
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]
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) -> 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;[src]
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;[src]Returns an iterator over the set elements. Elements will be returned in an arbitrary (unsorted) order.
pub fn get(&self, elem: &A::Item) -> Option<&A::Item>[src]
pub fn get(&self, elem: &A::Item) -> Option<&A::Item>[src]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).
pub fn take(&mut self, value: &A::Item) -> Option<A::Item>[src]
pub fn take(&mut self, value: &A::Item) -> Option<A::Item>[src]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.
pub fn replace(&mut self, value: A::Item) -> Option<A::Item>[src]
pub fn replace(&mut self, value: A::Item) -> Option<A::Item>[src]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;[src]
pub fn drain(&mut self) -> SmallDrain<A::Item>ⓘNotable traits for SmallDrain<T>
impl<T> Iterator for SmallDrain<T> type Item = T;[src]Empties the set and returns an iterator over it.
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&mut A::Item) -> bool + for<'r> FnMut(&'r <A as Array>::Item) -> bool, [src]
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&mut A::Item) -> bool + for<'r> FnMut(&'r <A as Array>::Item) -> bool, [src]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;[src]
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;[src]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;[src]
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;[src]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;[src]
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;[src]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;[src]
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;[src]Returns an iterator over the symmetric difference of the 2 sets.
Trait Implementations
impl<A: Array> FromIterator<<A as Array>::Item> for SmolSet<A> where
A::Item: PartialEq + Eq + Hash, [src]
impl<A: Array> FromIterator<<A as Array>::Item> for SmolSet<A> where
A::Item: PartialEq + Eq + Hash, [src]fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>, [src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>, [src]Creates a value from an iterator. Read more
Auto Trait Implementations
impl<A> RefUnwindSafe for SmolSet<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> Send for SmolSet<A> where
<A as Array>::Item: Send,
<A as Array>::Item: Send,
impl<A> Sync for SmolSet<A> where
A: Sync,
<A as Array>::Item: Sync,
A: Sync,
<A as Array>::Item: Sync,
impl<A> Unpin for SmolSet<A> where
A: Unpin,
<A as Array>::Item: Unpin,
A: Unpin,
<A as Array>::Item: Unpin,
impl<A> UnwindSafe for SmolSet<A> where
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe + UnwindSafe,
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more