pub trait SetOps {
// Required methods
fn contains(&self, value: &usize) -> bool;
fn iter(&self) -> Box<dyn Iterator<Item = &usize> + '_>;
fn max(&self) -> Option<usize>;
}
Expand description
Provides operations common to sets, such as containment check, iteration, and finding the maximum value.
Required Methods§
Implementations on Foreign Types§
source§impl SetOps for HashSet<usize>
impl SetOps for HashSet<usize>
source§fn contains(&self, value: &usize) -> bool
fn contains(&self, value: &usize) -> bool
Checks whether the set contains the specified value.
§Arguments
value
- The value to check for containment.
§Returns
true
if the set contains the value, otherwise false
.
§Examples
use std::collections::HashSet;
use fastset::SetOps;
let mut set = HashSet::new();
set.insert(42);
assert!(set.contains(&42));
assert!(!set.contains(&100));
source§fn iter(&self) -> Box<dyn Iterator<Item = &usize> + '_>
fn iter(&self) -> Box<dyn Iterator<Item = &usize> + '_>
Returns an iterator over the elements of the set.
§Returns
A boxed iterator yielding references to the elements of the set.
§Examples
use std::collections::HashSet;
use fastset::SetOps;
let mut set = HashSet::<usize>::new();
set.insert(42);
set.insert(100);
let mut results = Vec::new();
set.iter().for_each(|&elem| results.push(elem));
let expected = HashSet::from([42, 100]);
let results_set: HashSet<usize> = results.into_iter().collect();
assert_eq!(results_set, expected);