Struct smolset::SmolSet[][src]

pub struct SmolSet<A: Array> where
    A::Item: PartialEq + Eq
{ /* fields omitted */ }
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

Creates a new, empty SmolSet.

Returns the number of elements in this set.

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.

Returns an iterator over the set elements. Elements will be returned in an arbitrary (unsorted) order.

Returns the current length of the set.

Clears the set.

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.

Empties the set and returns an iterator over it.

Removes all elements in the set that does not satisfy the given predicate f.

Returns an iterator over the intersection of the 2 sets.

Returns an iterator over the union of the 2 sets.

Returns an iterator over the difference of the 2 sets.

Returns an iterator over the symmetric difference of the 2 sets.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Creates a value from an iterator. Read more

Implement into iterator for the SmolSet

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Implement into iterator for borrowed SmolSet

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.