[−][src]Struct smallset::SmallSet
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]
A::Item: PartialEq + Eq,
pub fn new() -> SmallSet<A>
[src]
Creates a new, empty SmallSet
.
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) -> Iter<A::Item>
[src]
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.
Trait Implementations
impl<A: Array> Clone for SmallSet<A> where
A::Item: PartialEq + Eq + Clone,
[src]
A::Item: PartialEq + Eq + Clone,
impl<A: Array> Debug for SmallSet<A> where
A::Item: PartialEq + Eq + Debug,
[src]
A::Item: PartialEq + Eq + Debug,
impl<A: Array> FromIterator<<A as Array>::Item> for SmallSet<A> where
A::Item: PartialEq + Eq,
[src]
A::Item: PartialEq + Eq,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>,
[src]
T: IntoIterator<Item = A::Item>,
Auto Trait Implementations
impl<A> RefUnwindSafe for SmallSet<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> Send for SmallSet<A> where
<A as Array>::Item: Send,
<A as Array>::Item: Send,
impl<A> Sync for SmallSet<A> where
A: Sync,
A: Sync,
impl<A> Unpin for SmallSet<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for SmallSet<A> where
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe,
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe,
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>,