[][src]Struct tinyset::set::Set

pub struct Set<T: Copy + Eq + Hash> { /* fields omitted */ }

A set that is a FnvHashSet when it has many elements, but is just an array for small set sizes.

As with the FnvHashSet type, a Set requires that the elements implement the Eq and Hash traits. This can frequently be achieved by using #[derive(PartialEq, Eq, Hash)]. In addition, Set requires that the elements implement the Copy trait, and really they should be pretty small, since Set always stores room for CAPACITY elements.

This set type may be wasteful if the elements are each large in size, since it always uses 8 times the size of a single element plus a discriminator. Sets of up to 8 elements (the current value of CAPACITY) are stored on the stack in a simple unordered array. Larger sets are stored in an FnvHashSet. It would be smarter to determine the number stored on the stack based on the element size, but that requires const functions.

Methods

impl<T: Copy + Eq + Hash> Set<T>[src]

pub fn new() -> Set<T>[src]

Creates an empty set..

pub fn default() -> Set<T>[src]

Creates an empty set..

pub fn with_capacity(cap: usize) -> Set<T>[src]

Creates an empty set with the specified capacity.

pub fn len(&self) -> usize[src]

Returns the number of elements in the set.

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more elements to be inserted in the set. The collection may reserve more space to avoid frequent reallocations.

pub fn insert(&mut self, elem: T) -> bool[src]

Adds a value to the set.

If the set did not have this value present, true is returned.

If the set did have this value present, false is returned.

pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool where
    T: Borrow<Q>,
    Q: Hash + Eq
[src]

Removes an element, and returns true if that element was present.

pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool where
    T: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns true if the set contains a value.

Important traits for Iter<'a, T>
pub fn iter(&self) -> Iter<T>[src]

Returns an iterator over the set.

Important traits for IntoIter<T>
pub fn drain(&mut self) -> IntoIter<T>[src]

Clears the set, returning all elements in an iterator.

Trait Implementations

impl<T: Eq + Hash + Copy> Extend<T> for Set<T>[src]

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)[src]

Adds a bunch of elements to the set

Examples

use tinyset::Set;

let mut a: Set<u32> = vec![1, 2, 3].into_iter().collect();
a.extend(vec![3, 4, 5]);

let mut i = 0;
let expected = [1, 2, 3, 4, 5];
for x in &a {
    assert!(expected.contains(x));
    i += 1;
}
assert_eq!(i, expected.len());

impl<T: Clone + Copy + Eq + Hash> Clone for Set<T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a, T: Eq + Hash + Copy> IntoIterator for &'a Set<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<T: Eq + Hash + Copy> IntoIterator for Set<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

Important traits for IntoIter<T>
fn into_iter(self) -> IntoIter<T>[src]

Creates a consuming iterator, that is, one that moves each value out of the set in arbitrary order. The set cannot be used after calling this.

Examples

use tinyset::Set;
let mut set: Set<u32> = Set::new();
set.insert(2);
set.insert(5);

// Not possible to collect to a Vec<String> with a regular `.iter()`.
let v: Vec<_> = set.into_iter().collect();

// Will print in an arbitrary order.
for x in &v {
    println!("{}", x);
}

impl<T: Debug + Copy + Eq + Hash> Debug for Set<T>[src]

impl<'a, 'b, T: Eq + Hash + Copy> Sub<&'b Set<T>> for &'a Set<T>[src]

type Output = Set<T>

The resulting type after applying the - operator.

fn sub(self, rhs: &Set<T>) -> Set<T>[src]

Returns the difference of self and rhs as a new Set<T>.

Examples

use tinyset::Set;

let a: Set<u32> = vec![1, 2, 3].into_iter().collect();
let b: Set<u32> = vec![3, 4, 5].into_iter().collect();

let set = &a - &b;

let mut i = 0;
let expected = [1, 2];
for x in &set {
    assert!(expected.contains(x));
    i += 1;
}
assert_eq!(i, expected.len());

impl<'a, 'b, T: Eq + Hash + Copy> BitOr<&'b Set<T>> for &'a Set<T>[src]

type Output = Set<T>

The resulting type after applying the | operator.

fn bitor(self, rhs: &Set<T>) -> Set<T>[src]

Returns the union of self and rhs as a new Set<T>.

Examples

use tinyset::Set;

let a: Set<u32> = vec![1, 2, 3].into_iter().collect();
let b: Set<u32> = vec![3, 4, 5].into_iter().collect();

let set = &a | &b;

let mut i = 0;
let expected = [1, 2, 3, 4, 5];
for x in &set {
    assert!(expected.contains(x));
    i += 1;
}
assert_eq!(i, expected.len());

impl<T: Hash + Copy + Eq> FromIterator<T> for Set<T>[src]

Auto Trait Implementations

impl<T> Send for Set<T> where
    T: Send

impl<T> Sync for Set<T> where
    T: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]