[−][src]Struct smolset::SmolSet
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]
A::Item: PartialEq + Eq + Hash,
pub fn new() -> SmolSet<A>
[src]
Creates a new, empty SmolSet
.
pub fn mode(&self) -> SetMode
[src]
pub fn is_empty(&self) -> bool
[src]
Returns the number of elements in this set.
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) -> 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]
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;
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.
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]
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]
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]
Notable traits for SmallDrain<T>
impl<T> Iterator for SmallDrain<T> type Item = T;
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]
F: FnMut(&mut A::Item) -> bool + for<'r> FnMut(&'r <A as Array>::Item) -> bool,
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]
&'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;
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]
Notable traits for SmallUnion<'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;
[src]
Notable traits for SmallDifference<'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;
[src]
&'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;
Returns an iterator over the symmetric difference of the 2 sets.
Trait Implementations
impl<A: Array> Clone for SmolSet<A> where
A::Item: PartialEq + Eq + Clone,
[src]
A::Item: PartialEq + Eq + Clone,
impl<A: Array> Debug for SmolSet<A> where
A::Item: PartialEq + Eq + Debug,
[src]
A::Item: PartialEq + Eq + Debug,
impl<A: Array> Default for SmolSet<A> where
A::Item: PartialEq + Eq + Hash,
[src]
A::Item: PartialEq + Eq + Hash,
impl<A: Array> FromIterator<<A as Array>::Item> for SmolSet<A> where
A::Item: PartialEq + Eq + Hash,
[src]
A::Item: PartialEq + Eq + Hash,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>,
[src]
T: IntoIterator<Item = A::Item>,
impl<A: Array> PartialEq<SmolSet<A>> for SmolSet<A> where
A::Item: Eq + PartialEq + Hash,
[src]
A::Item: Eq + PartialEq + Hash,
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,