Struct im::hashset::HashSet [−][src]
pub struct HashSet<A, S = RandomState> { /* fields omitted */ }
An unordered set.
An immutable hash set using hash array mapped tries.
Most operations on this set are O(logx n) for a
suitably high x that it should be nearly O(1) for most sets.
Because of this, it's a great choice for a generic set as long as
you don't mind that values will need to implement
Hash
and Eq
.
Values will have a predictable order based on the hasher being
used. Unless otherwise specified, all sets will use the default
RandomState
hasher,
which will produce consistent hashes for the duration of its
lifetime, but not between restarts of your program.
Methods
impl<A> HashSet<A, RandomState> where
A: Hash + Eq + Clone,
[src]
impl<A> HashSet<A, RandomState> where
A: Hash + Eq + Clone,
pub fn new() -> Self
[src]
pub fn new() -> Self
Construct an empty set.
pub fn singleton(a: A) -> Self
[src]
pub fn singleton(a: A) -> Self
Construct a set with a single value.
Examples
let set = HashSet::singleton(123); assert!(set.contains(&123));
impl<A, S> HashSet<A, S>
[src]
impl<A, S> HashSet<A, S>
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Test whether a set is empty.
Time: O(1)
Examples
assert!( !hashset![1, 2, 3].is_empty() ); assert!( HashSet::<i32>::new().is_empty() );
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
impl<A, S> HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<A, S> HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
pub fn with_hasher<RS>(hasher: RS) -> Self where
Rc<S>: From<RS>,
[src]
pub fn with_hasher<RS>(hasher: RS) -> Self where
Rc<S>: From<RS>,
Construct an empty hash set using the provided hasher.
pub fn hasher(&self) -> &Rc<S>
[src]
pub fn hasher(&self) -> &Rc<S>
Get a reference to the set's BuildHasher
.
pub fn new_from<A1>(&self) -> HashSet<A1, S> where
A1: Hash + Eq + Clone,
[src]
pub fn new_from<A1>(&self) -> HashSet<A1, S> where
A1: Hash + Eq + Clone,
Construct an empty hash set using the same hasher as the current hash set.
ⓘImportant traits for Iter<'a, A>pub fn iter(&self) -> Iter<A>
[src]
pub fn iter(&self) -> Iter<A>
Get an iterator over the values in a hash set.
Please note that the order is consistent between sets using the same hasher, but no other ordering guarantee is offered. Items will not come out in insertion order or sort order. They will, however, come out in the same order every time for the same set.
pub fn contains<BA: ?Sized>(&self, a: &BA) -> bool where
BA: Hash + Eq,
A: Borrow<BA>,
[src]
pub fn contains<BA: ?Sized>(&self, a: &BA) -> bool where
BA: Hash + Eq,
A: Borrow<BA>,
Test if a value is part of a set.
Time: O(log n)
pub fn insert(&mut self, a: A) -> Option<A>
[src]
pub fn insert(&mut self, a: A) -> Option<A>
Insert a value into a set.
Time: O(log n)
pub fn remove<BA: ?Sized>(&mut self, a: &BA) -> Option<A> where
BA: Hash + Eq,
A: Borrow<BA>,
[src]
pub fn remove<BA: ?Sized>(&mut self, a: &BA) -> Option<A> where
BA: Hash + Eq,
A: Borrow<BA>,
Remove a value from a set if it exists.
Time: O(log n)
pub fn update(&self, a: A) -> Self
[src]
pub fn update(&self, a: A) -> Self
Construct a new set from the current set with the given value added.
Time: O(log n)
Examples
let set = hashset![123]; assert_eq!( set.update(456), hashset![123, 456] );
pub fn without<BA: ?Sized>(&self, a: &BA) -> Self where
BA: Hash + Eq,
A: Borrow<BA>,
[src]
pub fn without<BA: ?Sized>(&self, a: &BA) -> Self where
BA: Hash + Eq,
A: Borrow<BA>,
Construct a new set with the given value removed if it's in the set.
Time: O(log n)
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&A) -> bool,
[src]
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&A) -> bool,
Filter out values from a set which don't satisfy a predicate.
This is slightly more efficient than filtering using an iterator, in that it doesn't need to rehash the retained values, but it still needs to reconstruct the entire tree structure of the set.
Time: O(n log n)
pub fn union(self, other: Self) -> Self
[src]
pub fn union(self, other: Self) -> Self
Construct the union of two sets.
Time: O(n log n)
Examples
let set1 = hashset!{1, 2}; let set2 = hashset!{2, 3}; let expected = hashset!{1, 2, 3}; assert_eq!(expected, set1.union(set2));
pub fn unions<I>(i: I) -> Self where
I: IntoIterator<Item = Self>,
S: Default,
[src]
pub fn unions<I>(i: I) -> Self where
I: IntoIterator<Item = Self>,
S: Default,
Construct the union of multiple sets.
Time: O(n log n)
pub fn difference(self, other: Self) -> Self
[src]
pub fn difference(self, other: Self) -> Self
Construct the difference between two sets.
Time: O(n log n)
Examples
let set1 = hashset!{1, 2}; let set2 = hashset!{2, 3}; let expected = hashset!{1, 3}; assert_eq!(expected, set1.difference(set2));
pub fn intersection(self, other: Self) -> Self
[src]
pub fn intersection(self, other: Self) -> Self
Construct the intersection of two sets.
Time: O(n log n)
Examples
let set1 = hashset!{1, 2}; let set2 = hashset!{2, 3}; let expected = hashset!{2}; assert_eq!(expected, set1.intersection(set2));
pub fn is_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
pub fn is_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
Test whether a set is a subset of another set, meaning that all values in our set must also be in the other set.
Time: O(n log n)
pub fn is_proper_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
pub fn is_proper_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
Test whether a set is a proper subset of another set, meaning that all values in our set must also be in the other set. A proper subset must also be smaller than the other set.
Time: O(n log n)
Trait Implementations
impl<A: Hash + Eq + Ord + Clone, S: BuildHasher> From<HashSet<A, S>> for OrdSet<A>
[src]
impl<A: Hash + Eq + Ord + Clone, S: BuildHasher> From<HashSet<A, S>> for OrdSet<A>
impl<'a, A: Hash + Eq + Ord + Clone, S: BuildHasher> From<&'a HashSet<A, S>> for OrdSet<A>
[src]
impl<'a, A: Hash + Eq + Ord + Clone, S: BuildHasher> From<&'a HashSet<A, S>> for OrdSet<A>
impl<A, S> Clone for HashSet<A, S> where
A: Clone,
[src]
impl<A, S> Clone for HashSet<A, S> where
A: Clone,
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<A, S> PartialEq for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> PartialEq for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<A, S> Eq for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> Eq for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A, S> PartialOrd for HashSet<A, S> where
A: Hash + Eq + Clone + PartialOrd,
S: BuildHasher + Default,
[src]
impl<A, S> PartialOrd for HashSet<A, S> where
A: Hash + Eq + Clone + PartialOrd,
S: BuildHasher + Default,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<A, S> Ord for HashSet<A, S> where
A: Hash + Eq + Clone + Ord,
S: BuildHasher + Default,
[src]
impl<A, S> Ord for HashSet<A, S> where
A: Hash + Eq + Clone + Ord,
S: BuildHasher + Default,
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<A, S> Hash for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> Hash for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<A, S> Default for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> Default for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A, S> Add for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<A, S> Add for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Output = HashSet<A, S>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
fn add(self, other: Self) -> Self::Output
Performs the +
operation.
impl<A, S> Mul for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<A, S> Mul for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Output = HashSet<A, S>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
fn mul(self, other: Self) -> Self::Output
Performs the *
operation.
impl<'a, A, S> Add for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<'a, A, S> Add for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Output = HashSet<A, S>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
fn add(self, other: Self) -> Self::Output
Performs the +
operation.
impl<'a, A, S> Mul for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<'a, A, S> Mul for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Output = HashSet<A, S>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
fn mul(self, other: Self) -> Self::Output
Performs the *
operation.
impl<A, S> Sum for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> Sum for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
fn sum<I>(it: I) -> Self where
I: Iterator<Item = Self>,
[src]
fn sum<I>(it: I) -> Self where
I: Iterator<Item = Self>,
Method which takes an iterator and generates Self
from the elements by "summing up" the items. Read more
impl<A, S, R> Extend<R> for HashSet<A, S> where
A: Hash + Eq + Clone + From<R>,
S: BuildHasher,
[src]
impl<A, S, R> Extend<R> for HashSet<A, S> where
A: Hash + Eq + Clone + From<R>,
S: BuildHasher,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
Extends a collection with the contents of an iterator. Read more
impl<A, S> Debug for HashSet<A, S> where
A: Hash + Eq + Clone + Debug,
S: BuildHasher + Default,
[src]
impl<A, S> Debug for HashSet<A, S> where
A: Hash + Eq + Clone + Debug,
S: BuildHasher + Default,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<A, RA, S> FromIterator<RA> for HashSet<A, S> where
A: Hash + Eq + Clone + From<RA>,
S: BuildHasher + Default,
[src]
impl<A, RA, S> FromIterator<RA> for HashSet<A, S> where
A: Hash + Eq + Clone + From<RA>,
S: BuildHasher + Default,
fn from_iter<T>(i: T) -> Self where
T: IntoIterator<Item = RA>,
[src]
fn from_iter<T>(i: T) -> Self where
T: IntoIterator<Item = RA>,
Creates a value from an iterator. Read more
impl<'a, A, S> IntoIterator for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<'a, A, S> IntoIterator for &'a HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Item = &'a A
The type of the elements being iterated over.
type IntoIter = Iter<'a, A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<A, S> IntoIterator for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
[src]
impl<A, S> IntoIterator for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher,
type Item = A
The type of the elements being iterated over.
type IntoIter = ConsumingIter<Self::Item>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'s, 'a, A: ?Sized, OA, SA, SB> From<&'s HashSet<&'a A, SA>> for HashSet<OA, SB> where
A: ToOwned<Owned = OA> + Hash + Eq,
OA: Borrow<A> + Hash + Eq + Clone,
SA: BuildHasher,
SB: BuildHasher + Default,
[src]
impl<'s, 'a, A: ?Sized, OA, SA, SB> From<&'s HashSet<&'a A, SA>> for HashSet<OA, SB> where
A: ToOwned<Owned = OA> + Hash + Eq,
OA: Borrow<A> + Hash + Eq + Clone,
SA: BuildHasher,
SB: BuildHasher + Default,
impl<'a, A, S> From<&'a [A]> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a [A]> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A, S> From<Vec<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> From<Vec<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<'a, A, S> From<&'a Vec<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a Vec<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A, S> From<HashSet<A>> for HashSet<A, S> where
A: Eq + Hash + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> From<HashSet<A>> for HashSet<A, S> where
A: Eq + Hash + Clone,
S: BuildHasher + Default,
impl<'a, A, S> From<&'a HashSet<A>> for HashSet<A, S> where
A: Eq + Hash + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a HashSet<A>> for HashSet<A, S> where
A: Eq + Hash + Clone,
S: BuildHasher + Default,
impl<'a, A, S> From<&'a BTreeSet<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a BTreeSet<A>> for HashSet<A, S> where
A: Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A, S> From<OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> From<OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
impl<'a, A, S> From<&'a OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
Auto Trait Implementations
impl<A, S = RandomState> !Send for HashSet<A, S>
impl<A, S = RandomState> !Send for HashSet<A, S>
impl<A, S = RandomState> !Sync for HashSet<A, S>
impl<A, S = RandomState> !Sync for HashSet<A, S>