Struct vec_collections::VecSet [−][src]
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; 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; 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
impl<A: Array> VecSet<A>
[src]
pub fn single(value: A::Item) -> Self
[src]
A set with a single element.
pub fn empty() -> Self
[src]
The empty set.
pub fn iter(&self) -> VecSetIter<Iter<'_, A::Item>>ⓘNotable traits for VecSetIter<I>
impl<I: Iterator> Iterator for VecSetIter<I> type Item = I::Item;
[src]
Notable traits for VecSetIter<I>
impl<I: Iterator> Iterator for VecSetIter<I> type Item = I::Item;
An iterator that returns references to the items of this set in sorted order
pub fn len(&self) -> usize
[src]
The number of elements in the set.
pub fn shrink_to_fit(&mut self)
[src]
Shrink the underlying SmallVec
pub fn is_empty(&self) -> bool
[src]
true if the set is empty.
pub fn into_inner(self) -> SmallVec<A>
[src]
Returns the wrapped SmallVec.
impl<A: Array> VecSet<A> where
A::Item: Ord,
[src]
A::Item: Ord,
pub fn insert(&mut self, that: A::Item) -> bool
[src]
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.
pub fn remove(&mut self, that: &A::Item) -> bool
[src]
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.
pub fn retain<F: FnMut(&A::Item) -> bool>(&mut self, f: F)
[src]
Retain all elements matching a predicate.
pub fn is_disjoint<B: Array<Item = A::Item>>(&self, that: &VecSet<B>) -> bool
[src]
true if this set has no common elements with another set.
pub fn is_subset<B: Array<Item = A::Item>>(&self, that: &VecSet<B>) -> bool
[src]
true if this set is a subset of another set.
A set is considered to be a subset of itself.
pub fn is_superset<B: Array<Item = A::Item>>(&self, that: &VecSet<B>) -> bool
[src]
true if this set is a superset of another set.
A set is considered to be a superset of itself.
pub fn contains(&self, value: &A::Item) -> bool
[src]
true if this set contains the item.
Time complexity is O(log N). Binary search.
Trait Implementations
impl<A: Array> AsRef<[<A as Array>::Item]> for VecSet<A>
[src]
impl<T: Ord + Clone, Arr: Array<Item = T>, B: Array<Item = T>> BitAnd<&'_ VecSet<B>> for &VecSet<Arr>
[src]
type Output = VecSet<Arr>
The resulting type after applying the &
operator.
fn bitand(self, that: &VecSet<B>) -> Self::Output
[src]
impl<T: Ord, A: Array<Item = T>, B: Array<Item = T>> BitAndAssign<VecSet<B>> for VecSet<A>
[src]
fn bitand_assign(&mut self, that: VecSet<B>)
[src]
impl<T: Ord + Clone, A: Array<Item = T>, B: Array<Item = T>> BitOr<&'_ VecSet<B>> for &VecSet<A>
[src]
type Output = VecSet<A>
The resulting type after applying the |
operator.
fn bitor(self, that: &VecSet<B>) -> Self::Output
[src]
impl<T: Ord, A: Array<Item = T>, B: Array<Item = T>> BitOrAssign<VecSet<B>> for VecSet<A>
[src]
fn bitor_assign(&mut self, that: VecSet<B>)
[src]
impl<T: Ord + Clone, A: Array<Item = T>, B: Array<Item = T>> BitXor<&'_ VecSet<B>> for &VecSet<A>
[src]
type Output = VecSet<A>
The resulting type after applying the ^
operator.
fn bitxor(self, that: &VecSet<B>) -> Self::Output
[src]
impl<T: Ord, A: Array<Item = T>, B: Array<Item = T>> BitXorAssign<VecSet<B>> for VecSet<A>
[src]
fn bitxor_assign(&mut self, that: VecSet<B>)
[src]
impl<T: Clone, A: Array<Item = T>> Clone for VecSet<A>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug, A: Array<Item = T>> Debug for VecSet<A>
[src]
impl<A: Default + Array> Default for VecSet<A>
[src]
impl<'de, A: Array> Deserialize<'de> for VecSet<A> where
A::Item: Deserialize<'de> + Ord,
[src]
A::Item: Deserialize<'de> + Ord,
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
[src]
impl<T: Eq, A: Array<Item = T>> Eq for VecSet<A>
[src]
impl<T: Ord, A: Array<Item = T>> Extend<T> for VecSet<A>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T: Ord, A: Array<Item = T>> From<BTreeSet<T>> for VecSet<A>
[src]
Provides a way to create a VecSet from a BTreeSet without having to sort again
impl<T: Ord, A: Array<Item = T>> From<Vec<T, Global>> for VecSet<A>
[src]
impl<A: Array> From<VecMap<A>> for VecSet<A>
[src]
impl<T: Ord, A: Array<Item = T>> FromIterator<T> for VecSet<A>
[src]
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).
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T: Hash, A: Array<Item = T>> Hash for VecSet<A>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A: Array> Into<SmallVec<A>> for VecSet<A>
[src]
impl<A: Array> Into<Vec<<A as Array>::Item, Global>> for VecSet<A>
[src]
impl<'a, A: Array> IntoIterator for &'a VecSet<A>
[src]
type Item = &'a A::Item
The type of the elements being iterated over.
type IntoIter = VecSetIter<Iter<'a, A::Item>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<A: Array> IntoIterator for VecSet<A>
[src]
type Item = A::Item
The type of the elements being iterated over.
type IntoIter = VecSetIter<IntoIter<A>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Ord, A: Array<Item = T>> Ord for VecSet<A>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq, A: Array<Item = T>> PartialEq<VecSet<A>> for VecSet<A>
[src]
impl<T: PartialOrd, A: Array<Item = T>> PartialOrd<VecSet<A>> for VecSet<A>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A: Array> Serialize for VecSet<A> where
A::Item: Serialize,
[src]
A::Item: Serialize,
impl<T: Ord + Clone, A: Array<Item = T>, B: Array<Item = T>> Sub<&'_ VecSet<B>> for &VecSet<A>
[src]
type Output = VecSet<A>
The resulting type after applying the -
operator.
fn sub(self, that: &VecSet<B>) -> Self::Output
[src]
impl<T: Ord, A: Array<Item = T>, B: Array<Item = T>> SubAssign<VecSet<B>> for VecSet<A>
[src]
fn sub_assign(&mut self, that: VecSet<B>)
[src]
Auto Trait Implementations
impl<A> RefUnwindSafe for VecSet<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> Send for VecSet<A> where
<A as Array>::Item: Send,
<A as Array>::Item: Send,
impl<A> Sync for VecSet<A> where
A: Sync,
A: Sync,
impl<A> Unpin for VecSet<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for VecSet<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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
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.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,