Trait fastset::SetOps

source ·
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§

source

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 fastset::{Set, SetOps, set};

let set = set![42];
assert!(set.contains(&42));
assert!(!set.contains(&100));
source

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 fastset::{Set, SetOps, set};

let set = set![1, 2, 3, 4, 5];
for item in set.iter() {
    println!("{}", *item);
}
source

fn max(&self) -> Option<usize>

Returns the maximum value in the set, if any.

§Returns

The maximum value in the set, or None if the set is empty.

§Examples
use fastset::{Set, insert};

let mut set = Set::new(2);
insert!(set, 2, 42);
assert_eq!(set.max(), Some(42));

Implementations on Foreign Types§

source§

impl SetOps for HashSet<usize>

source§

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> + '_>

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);
source§

fn max(&self) -> Option<usize>

Returns the maximum value in the set, if any.

§Returns

The maximum value in the set, or None if the set is empty.

§Examples
use std::collections::HashSet;
use fastset::SetOps;

let mut set = HashSet::new();
set.insert(42);
set.insert(100);

assert_eq!(set.max(), Some(100));

Implementors§