Struct rust_algorithm_club::collections::HashSet
source · [−]Expand description
A hash set implementation based on HashMap
.
References:
Implementations
sourceimpl<T> HashSet<T> where
T: Hash + Eq,
impl<T> HashSet<T> where
T: Hash + Eq,
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Gets the number of non-repetitive elements, equivalently to the cardinality of a set.
Complexity
Constant.
sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Inserts an element into the set.
Returns true
if there were no such element in the set; returns false
if an identical element is already in the set.
Parameters
value
- Element to be inserted.
Complexity
Constant.
sourcepub fn contains<Q>(&self, value: &Q) -> bool where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
pub fn contains<Q>(&self, value: &Q) -> bool where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns whether an element is present in the set.
This is equivalent to “belongs to ∈” relation in mathematics.
Parameters
value
- Element to be checked whether is in the set.
Complexity
Constant.
sourcepub fn remove<Q>(&mut self, value: &Q) -> bool where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
pub fn remove<Q>(&mut self, value: &Q) -> bool where
T: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Removes an element from the set.
Returns true
if such item was present and removed; returns false
if no such item was found in the set.
Parameters
value
- Element to be removed.
Complexity
Constant.
sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Creates an iterator yielding immutable reference of each item in arbitrary order.
sourcepub fn union<'a>(&'a self, other: &'a HashSet<T>) -> impl Iterator<Item = &T>
pub fn union<'a>(&'a self, other: &'a HashSet<T>) -> impl Iterator<Item = &T>
Returns an iterator visiting items that exists in self
, in other
,
or in both self
and other
This is equivalent to self ∪ other
in mathematics.
Parameters
other
- The other set.
sourcepub fn difference<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
pub fn difference<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
Returns an iterator visiting items that exists in self
but not in other
.
This is equivalent to self \ other
in mathematics.
Parameters
other
- The other set.
sourcepub fn symmetric_difference<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
pub fn symmetric_difference<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
Returns an iterator visiting items that only exists in either self
or
other
but not in their intersection.
This is equivalent to self △ other
in mathematics.
Parameters
other
- The other set.
sourcepub fn intersection<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
pub fn intersection<'a>(
&'a self,
other: &'a HashSet<T>
) -> impl Iterator<Item = &T>
Returns an iterator visiting items that exists in both self
and other
.
This is equivalent to self ∩ other
in mathematics.
Parameters
other
- The other set.
sourcepub fn is_disjoint(&self, other: &HashSet<T>) -> bool
pub fn is_disjoint(&self, other: &HashSet<T>) -> bool
Returns true if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection, which means their intersection is the empty set ∅.
Parameters
other
- The other set.
Complexity
Linear in the size of self
.
sourcepub fn is_subset(&self, other: &HashSet<T>) -> bool
pub fn is_subset(&self, other: &HashSet<T>) -> bool
Returns true if other
contains at least all elements in self
.
This is equivalent to self ⊆ other
in mathematics.
Parameters
other
- The other set.
Complexity
Linear in the size of self
.
sourcepub fn is_superset(&self, other: &HashSet<T>) -> bool
pub fn is_superset(&self, other: &HashSet<T>) -> bool
Returns true if self
contains at least all elements in other
.
This is equivalent to self ⊇ other
in mathematics.
Parameters
other
- The other set.
Complexity
Linear in the size of other
.
Trait Implementations
sourceimpl<'a, 'b, T> BitAnd<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
impl<'a, 'b, T> BitAnd<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
The bit_and operator &
, as an alias of intersection().
sourceimpl<'a, 'b, T> BitOr<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
impl<'a, 'b, T> BitOr<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
The bitor operator |
, as an alias of union()
.
sourceimpl<'a, 'b, T> BitXor<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
impl<'a, 'b, T> BitXor<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
The bitxor operator ^
, as an alias of symmetric_difference()
.
sourceimpl<T> FromIterator<T> for HashSet<T> where
T: Hash + Eq,
impl<T> FromIterator<T> for HashSet<T> where
T: Hash + Eq,
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
sourceimpl<T> PartialEq<HashSet<T>> for HashSet<T> where
T: Hash + Eq,
impl<T> PartialEq<HashSet<T>> for HashSet<T> where
T: Hash + Eq,
sourcefn eq(&self, other: &HashSet<T>) -> bool
fn eq(&self, other: &HashSet<T>) -> bool
Checks the equality of sets.
Two sets are defined to be equal if they contain the same elements and their cardinality are equal.
Set theory definition: x = y ⇒ ∀z, (z ∈ x ⇔ z ∈ y)
Parameters
other
- The other set.
Complexity
Linear in the size of self
.
sourceimpl<T> PartialOrd<HashSet<T>> for HashSet<T> where
T: Hash + Eq,
impl<T> PartialOrd<HashSet<T>> for HashSet<T> where
T: Hash + Eq,
sourcefn partial_cmp(&self, other: &HashSet<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &HashSet<T>) -> Option<Ordering>
Compares sets to determine whether one is a subset of the other or not.
Parameters
other
- The other set.
Complexity
Linear in the size of max(self, other)
.
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl<'a, 'b, T> Sub<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
impl<'a, 'b, T> Sub<&'b HashSet<T>> for &'a HashSet<T> where
T: Hash + Eq + Clone,
The sub operator -
, as an alias of difference()
.
impl<T> Eq for HashSet<T> where
T: Hash + Eq,
A set is reflecxively equal to itself.
Auto Trait Implementations
impl<T> RefUnwindSafe for HashSet<T> where
T: RefUnwindSafe,
impl<T> Send for HashSet<T> where
T: Send,
impl<T> Sync for HashSet<T> where
T: Sync,
impl<T> Unpin for HashSet<T> where
T: Unpin,
impl<T> UnwindSafe for HashSet<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more