Struct vec_collections::VecSet[][src]

pub struct VecSet<A: Array>(_);
Expand description

A set backed by a SmallVec of elements.

A the underlying storage. This must be an array. The size of this array is the maximum size this collection can hold without allocating. VecSet is just a wrapper around a SmallVec, so it does not have additional memory overhead.

Sets support comparison operations ( is_disjoint, is_subset, is_superset ) and set combine operations ( bitand, bitor, bitxor, sub ). They also support in place operations ( bitand_assign, bitor_assign, bitxor_assign, sub_assign ) that will try to avoid allocations.

Creation

The best way to create a VecSet is to use FromIterator, via collect.

use vec_collections::VecSet;
let a: VecSet<[u32; 4]> = (0..4).collect(); // does not allocate

General usage

use vec_collections::{VecSet, AbstractVecSet};
let a: VecSet<[u32; 4]> = (0..4).collect(); // does not allocate
let b: VecSet<[u32; 2]> = (4..6).collect(); // does not allocate
println!("{}", a.is_disjoint(&b)); // true
let c = &a | &b; // underlying smallvec will spill over to the heap
println!("{}", c.contains(&5)); // true

In place operations

use vec_collections::{VecSet, AbstractVecSet};
let mut a: VecSet<[u32; 4]> = (0..4).collect(); // does not allocate
let b: VecSet<[u32; 4]> = (2..6).collect(); // does not allocate
a &= b; // in place intersection, will yield 2..4, will not allocate
println!("{}", a.contains(&3)); // true

Accessing the elements as a slice

Since a VecSet is a succinct collection, you can get a reference to the contents as a slice.

Example: choosing a random element

use vec_collections::VecSet;
use rand::seq::SliceRandom;
let mut a: VecSet<[u32; 4]> = (0..4).collect(); // does not allocate
let mut rng = rand::thread_rng();
let e = a.as_ref().choose(&mut rng).unwrap();
println!("{}", e);

Implementations

A set with a single element.

The empty set.

An iterator that returns references to the items of this set in sorted order

The number of elements in the set.

Shrink the underlying SmallVec to fit.

true if the set is empty.

Returns the wrapped SmallVec.

insert an element.

The time complexity of this is O(N), so building a large set using single element inserts will be slow! Prefer using from_iter when building a large VecSet from elements.

Remove an element.

The time complexity of this is O(N), so removing many elements using single element removes inserts will be slow! Prefer using retain when removing a large number of elements.

Retain all elements matching a predicate.

Trait Implementations

true if this set has no common elements with another set.

true if this set is a subset of another set. Read more

true if this set is a superset of another set. Read more

An iterator that returns references to the items of this set in sorted order

Performs the conversion.

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Extends a collection with the contents of an iterator. Read more

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

Extends a collection with exactly one element.

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

Reserves capacity in a collection for the given number of additional elements. Read more

Provides a way to create a VecSet from a BTreeSet without having to sort again

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Builds the set from an iterator.

Uses a heuristic to deduplicate while building the set, so the intermediate storage will never be more than twice the size of the resulting set. This is the most efficient way to build a large VecSet, significantly more efficient than single element insertion.

Worst case performance is O(log(n)^2 * n), but performance for already partially sorted collections will be significantly better. For a fully sorted collection, performance will be O(n).

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

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

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 returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

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)

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.