Struct collections::hashmap::HashSet
pub struct HashSet<T, H> { // some fields omitted }
An implementation of a hash set using the underlying representation of a
HashMap where the value is (). As with the HashMap
type, a HashSet
requires that the elements implement the Eq
and Hash
traits.
Methods
impl<T: Hash + TotalEq> HashSet<T, SipHasher>
fn new() -> HashSet<T, SipHasher>
Create an empty HashSet
fn with_capacity(capacity: uint) -> HashSet<T, SipHasher>
Create an empty HashSet with space for at least n
elements in
the hash table.
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> HashSet<T, H>
fn with_hasher(hasher: H) -> HashSet<T, H>
fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet<T, H>
Create an empty HashSet with space for at least capacity
elements in the hash table, using hasher
to hash the keys.
Warning: hasher
is normally randomly generated, and
is designed to allow HashSet
s to be resistant to attacks that
cause many collisions and very poor performance. Setting it
manually using this function can expose a DoS attack vector.
fn reserve(&mut self, n: uint)
Reserve space for at least n
elements in the hash table.
fn contains_equiv<Q: Hash<S> + Equiv<T>>(&self, value: &Q) -> bool
Returns true if the hash set contains a value equivalent to the given query value.
fn iter<'a>(&'a self) -> SetItems<'a, T>
An iterator visiting all elements in arbitrary order. Iterator element type is &'a T.
fn move_iter(self) -> SetMoveItems<T>
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.
fn difference<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H>
Visit the values representing the difference
fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, H>) -> Chain<SetAlgebraItems<'a, T, H>, SetAlgebraItems<'a, T, H>>
Visit the values representing the symmetric difference
fn intersection<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H>
Visit the values representing the intersection
fn union<'a>(&'a self, other: &'a HashSet<T, H>) -> Chain<SetItems<'a, T>, SetAlgebraItems<'a, T, H>>
Visit the values representing the union
Trait Implementations
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H>
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> Container for HashSet<T, H>
fn len(&self) -> uint
Return the number of elements in the set
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> Mutable for HashSet<T, H>
fn clear(&mut self)
Clear the set, removing all values.
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> Set<T> for HashSet<T, H>
fn contains(&self, value: &T) -> bool
Return true if the set contains a value
fn is_disjoint(&self, other: &HashSet<T, H>) -> bool
Return true if the set has no elements in common with other
.
This is equivalent to checking for an empty intersection.
fn is_subset(&self, other: &HashSet<T, H>) -> bool
Return true if the set is a subset of another
fn is_superset(&self, other: &HashSet<T, H>) -> bool
Return true if the set is a superset of another
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H>
fn insert(&mut self, value: T) -> bool
Add a value to the set. Return true if the value was not already present in the set.
fn remove(&mut self, value: &T) -> bool
Remove a value from the set. Return true if the value was present in the set.