Struct lib_rapid::math::sets::wrapper_hash_sets::WrapperHashSet
source · pub struct WrapperHashSet<'a, T, S = RandomState> {
pub hs: HashSet<T, S>,
/* private fields */
}
Expand description
A wrapper for the HashSet type which implements more functions.
Everything you need to do with a HashSet needs to be done using WrapperHashSet.hs.[function]
for now.
Fields§
§hs: HashSet<T, S>
The basic Hashset.
Implementations§
source§impl<'a, T: Clone + Eq + Hash> WrapperHashSet<'a, T>
impl<'a, T: Clone + Eq + Hash> WrapperHashSet<'a, T>
sourcepub fn wrap(existing: HashSet<T>) -> WrapperHashSet<'a, T>
pub fn wrap(existing: HashSet<T>) -> WrapperHashSet<'a, T>
Wrap a existing HashSet in this Wrapper-struct.
Arguments
existing
- The existing HashSet.
Returns
A new WrapperHashSet
.
Examples
use lib_rapid::math::sets::wrapper_hash_sets::WrapperHashSet;
use std::collections::HashSet;
let mut books = HashSet::new();
books.insert("A Dance With Dragons".to_string());
books.insert("1984".to_string());
let mut wrapped = WrapperHashSet::wrap(books);
sourcepub fn new_subset<F: Fn(&T) -> bool>(&'a self, f: F) -> Self
pub fn new_subset<F: Fn(&T) -> bool>(&'a self, f: F) -> Self
Creates a new WrapperHashSet
from self
to which it applies a closure.
Arguments
f
- The closure after which the newVecSet
is created.
Returns
A child WrapperHashSet
.
Examples
use lib_rapid::math::sets::wrapper_hash_sets::WrapperHashSet;
use std::collections::HashSet;
let mut nums = HashSet::new();
for i in 0..=6 {
nums.insert(i);
}
let wrapped = WrapperHashSet::wrap(nums);
let subset = wrapped.new_subset(|x| x % 2 == 0);
assert_eq!(HashSet::from([0, 2, 4, 6]), subset.hs);
sourcepub fn has_emerged(&self) -> bool
pub fn has_emerged(&self) -> bool
Lets you check wether a set has a parent (emerged from another set) or not.
Returns
A boolean value which determines if the set is a subset of any other set.
Examples
use lib_rapid::math::sets::wrapper_hash_sets::WrapperHashSet;
use std::collections::HashSet;
let mut nums = HashSet::new();
for i in 0..=6 {
nums.insert(i);
}
let wrapped = WrapperHashSet::wrap(nums);
let subset = wrapped.new_subset(|x| x % 2 == 0);
assert_eq!(true, subset.has_emerged());
sourcepub fn get_superset(&self) -> Option<&Self>
pub fn get_superset(&self) -> Option<&Self>
Gets you the optional superset.
Returns
A Option<&VecSet<T>>
.
Examples
use lib_rapid::math::sets::wrapper_hash_sets::WrapperHashSet;
use std::collections::HashSet;
let mut nums = HashSet::new();
for i in 0..=6 {
nums.insert(i);
}
let wrapped = WrapperHashSet::wrap(nums);
let subset = wrapped.new_subset(|x| x % 2 == 0);
assert_eq!(&wrapped, subset.get_superset().unwrap());
Trait Implementations§
source§impl<'a, T: Debug> Display for WrapperHashSet<'a, T>
impl<'a, T: Debug> Display for WrapperHashSet<'a, T>
source§impl<'a, T: Eq + Hash, S: BuildHasher> PartialEq for WrapperHashSet<'a, T, S>
impl<'a, T: Eq + Hash, S: BuildHasher> PartialEq for WrapperHashSet<'a, T, S>
source§fn eq(&self, other: &WrapperHashSet<'_, T, S>) -> bool
fn eq(&self, other: &WrapperHashSet<'_, T, S>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.Auto Trait Implementations§
impl<'a, T, S> RefUnwindSafe for WrapperHashSet<'a, T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, S> Send for WrapperHashSet<'a, T, S>
impl<'a, T, S> Sync for WrapperHashSet<'a, T, S>
impl<'a, T, S> Unpin for WrapperHashSet<'a, T, S>
impl<'a, T, S> UnwindSafe for WrapperHashSet<'a, T, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more