Struct fastset::Set

source ·
pub struct Set { /* private fields */ }
Expand description

Represents a custom Set implementation.

Implementations§

source§

impl Set

source

pub fn new(max_element: usize) -> Self

Creates a new Set with the specified maximum element.

§Arguments
  • max_element - The maximum element that the Set can contain.
§Examples
use fastset::Set;

// Create a new Set with a maximum capacity of 100 elements.
let set = Set::new(100);
source

pub fn with_capacity(capacity: usize) -> Self

Creates a new Set with the specified initial capacity.

The with_capacity method creates a new Set with the specified initial capacity. This allows you to pre-allocate memory for the Set if you know in advance how many elements it will contain.

§Arguments
  • capacity - The initial capacity of the Set.
§Examples
use fastset::Set;

// Create a new Set with an initial capacity of 50 elements.
let set = Set::with_capacity(50);
source

pub fn capacity(&self) -> usize

Returns the capacity of the Set.

The capacity of a Set is the maximum number of elements it can hold without allocating additional memory.

§Examples
use fastset::Set;

let mut set = Set::with_capacity(50);
assert_eq!(set.capacity(), 50);
source

pub fn reserve(&mut self, new_max_element: usize)

Reserves capacity for at least new_max_element additional elements in the Set.

If the current capacity of the Set is less than new_max_element, it will be increased to accommodate at least new_max_element elements. This method does nothing if the current capacity is already sufficient.

§Arguments
  • new_max_element - The new maximum element that the Set can contain.
§Examples
use fastset::Set;

let mut set = Set::new(100);

// Reserve capacity for at least 200 elements.
set.reserve(200);
source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the Set to the specified minimum capacity.

It will reduce the capacity of the Set to fit the specified min_capacity. If the current capacity is already smaller than min_capacity, this method does nothing.

§Arguments
  • min_capacity - The minimum capacity to reserve after shrinking.
§Examples
use fastset::{set, Set};

let mut set = Set::with_capacity(10);

set.insert(1);
set.insert(2);
set.insert(3);
assert!(set.capacity() >= 10);
set.shrink_to(4);
assert!(set.capacity() >= 4);
set.shrink_to(0);
assert!(set.capacity() >= 3);
source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the Set as much as possible.

This method is the same as shrink_to and exists for compatibility reasons.

§Examples
use fastset::Set;

let mut set = Set::with_capacity(10);
set.insert(1);
set.insert(2);
set.insert(3);
assert!(set.capacity() >= 10);
set.shrink_to_fit();
assert!(set.capacity() >= 3);
source

pub fn len(&self) -> usize

Returns the number of elements in the Set.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert_eq!(set.len(), 2);
source

pub fn is_empty(&self) -> bool

Returns true if the Set contains no elements, otherwise false.

§Examples
use fastset::Set;

let mut set = Set::new(100);
assert!(set.is_empty());

set.insert(5);
assert!(!set.is_empty());
source

pub fn iter(&self) -> Iter<'_, usize>

Returns an iterator over the elements in the Set.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

for element in set.iter() {
    println!("Element: {}", element);
}
source

pub fn clear(&mut self)

Removes all elements from the Set.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert!(!set.is_empty());

set.clear();

assert!(set.is_empty());
source

pub fn insert(&mut self, value: usize) -> bool

Inserts an element into the Set.

Returns true if the element was successfully inserted, and false if the element was already present in the Set.

§Arguments
  • value - The value to insert into the Set.
§Examples
use fastset::Set;

let mut set = Set::new(100);

// Inserting a new element
assert!(set.insert(5));

// Inserting a duplicate element
assert!(!set.insert(5));
source

pub fn remove(&mut self, value: &usize) -> bool

Removes an element from the Set.

Returns true if the element was successfully removed, and false if the element was not present in the Set.

§Arguments
  • value - The value to remove from the Set.
§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);

// Removing an existing element
assert!(set.remove(&5));

// Trying to remove a non-existing element
assert!(!set.remove(&10));
source

pub fn contains(&self, value: &usize) -> bool

Checks if the Set contains a specific value.

Returns true if the Set contains the specified value, and false otherwise.

§Arguments
  • value - The value to check for presence in the Set.
§Safety

This method uses unsafe pointer arithmetic to access elements of the internal indicator vector. However, it is safe because it performs a bound check on the value, ensuring that no out-of-bounds access occurs.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);

assert!(set.contains(&5));
assert!(!set.contains(&10));
source

pub fn get(&self, value: &usize) -> Option<usize>

Retrieves the specified value from the Set, if it exists.

Returns Some(value) if the Set contains the specified value, and None otherwise.

§Arguments
  • value - The value to retrieve from the Set.
§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);

assert_eq!(set.get(&5), Some(5));
assert_eq!(set.get(&10), None);
source

pub fn take(&mut self, value: &usize) -> Option<usize>

Removes and returns the specified value from the Set, if it exists.

Returns Some(value) if the Set contains the specified value and it was successfully removed, and None otherwise.

§Arguments
  • value - The value to remove from the Set.
§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);

assert_eq!(set.take(&5), Some(5));
assert_eq!(set.contains(&5), false);
source

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

Returns the maximum value in the Set, if it is not empty.

Returns Some(max) if the Set is not empty, and None if it is empty.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert_eq!(set.max(), Some(10));
source

pub fn min(&self) -> Option<usize>

Returns the minimum value in the Set, if it is not empty.

Returns Some(min) if the Set is not empty, and None if it is empty.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert_eq!(set.min(), Some(5));
source

pub fn range_cardinality<R>(&self, range: R) -> usize
where R: RangeBounds<usize>,

Returns the number of elements in the Set that fall within the specified range.

The range is defined by the provided range bounds, inclusive on the start bound and exclusive on the end bound. The method counts the elements within the range that exist in the Set.

§Arguments
  • range - The range of values to count elements for.
§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);
set.insert(15);

assert_eq!(set.range_cardinality(8..=12), 1);
source

pub fn rank(&self, value: usize) -> usize

Returns the number of elements in the Set that are strictly less than the specified value.

This method returns the count of elements in the Set that are less than the given value.

§Arguments
  • value - The value to compare against.
§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);
set.insert(15);

assert_eq!(set.rank(12), 2);
source

pub fn remove_largest(&mut self) -> Option<usize>

Removes and returns the largest value in the Set, if it is not empty.

Returns Some(value) if the Set is not empty, and None if it is empty.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert_eq!(set.remove_largest(), Some(10));
assert_eq!(set.contains(&10), false);
source

pub fn remove_smallest(&mut self) -> Option<usize>

Removes and returns the smallest value in the Set, if it is not empty.

Returns Some(value) if the Set is not empty, and None if it is empty.

§Examples
use fastset::Set;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);

assert_eq!(set.remove_smallest(), Some(5));
assert_eq!(set.contains(&5), false);
source

pub fn random(&self, rng: &mut WyRand) -> Option<usize>

Returns a random element from the Set using the provided random number generator.

If the Set is empty, returns None. Otherwise, returns a reference to a randomly chosen element.

§Arguments
  • rng - A mutable reference to a random number generator implementing the Rng trait.
§Safety

This method relies on unsafe code due to pointer arithmetic to avoid bounds checks for performance reasons.

§Examples
use fastset::Set;
use nanorand::WyRand;

let mut set = Set::new(100);
set.insert(5);
set.insert(10);
set.insert(15);

let mut rng = WyRand::new();
let random_element = set.random(&mut rng);
assert!(random_element.is_some());
source

pub fn insert_unchecked(&mut self, value: usize) -> bool

Inserts a value into the Set without performing bounds checks.

§Safety

This method relies on unsafe code due to pointer arithmetic to avoid bounds checks for performance reasons. Safety is ensured by the caller:

  1. value must be within the bounds of the indicator vector (respect the declared max_element during construction) avoiding out-of-bounds pointer arithmetic.
  2. There are no concurrent mutable references to indicator, index, or elements, ensuring no mutable aliasing occurs.
§Arguments
  • value - The value to be inserted into the Set.
§Returns

Returns true if the value was inserted, false if it was already present in the Set.

§Examples
use fastset::Set;

let mut set = Set::new(100);

// Inserting values without performing bounds checks.
unsafe {
    set.insert_unchecked(5);
    set.insert_unchecked(10);
}
source

pub fn remove_unchecked(&mut self, value: &usize) -> bool

Removes a value from the Set without performing bounds checks.

§Safety

This method relies on unsafe code due to pointer arithmetic to avoid bounds checks for performance reasons. Safety is ensured by the caller:

  1. value must be within the bounds of the indicator vector, avoiding out-of-bounds pointer arithmetic.
  2. There are no concurrent mutable references to indicator, index, or elements, ensuring no mutable aliasing occurs.
§Arguments
  • value - The value to be removed from the Set.
§Returns

Returns true if the value was removed, false if it was not present in the Set.

§Examples
use fastset::Set;

let mut set = Set::new(100);

// Inserting and removing values without performing bounds checks.
unsafe {
    set.insert_unchecked(5);
    set.insert_unchecked(10);
    set.remove_unchecked(&5);
}
source§

impl Set

source

pub fn is_subset<T: SetOps>(&self, other: &T) -> bool

Checks if the set is a subset of another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns true if all elements of the set are contained within the other set, otherwise false.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(1..=10);

assert!(set1.is_subset(&set2));
source

pub fn is_superset<T: SetOps>(&self, other: &T) -> bool

Checks if the set is a superset of another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns true if all elements of the other set are contained within this set, otherwise false.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=10);
let set2 = Set::from_iter(1..=5);

assert!(set1.is_superset(&set2));
source

pub fn is_disjoint<T: SetOps>(&self, other: &T) -> bool

Checks if the set has no elements in common with another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns true if the two sets have no elements in common, otherwise false.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(6..=10);

assert!(set1.is_disjoint(&set2));
source

pub fn union<T: SetOps>(&self, other: &T) -> Self

Returns the union of the set with another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns a new Set containing all elements present in either set.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(4..=8);

let union = set1.union(&set2);

assert_eq!(union.len(), 8);
source

pub fn intersection<T: SetOps>(&self, other: &T) -> Self

Returns the intersection of the set with another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns a new Set containing only elements present in both sets.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(4..=8);

let intersection = set1.intersection(&set2);

assert_eq!(intersection.len(), 2);
source

pub fn difference<T: SetOps>(&self, other: &T) -> Self

Returns the difference of the set with another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns a new Set containing elements present in the first set but not in the second set.

§Examples
use fastset::Set;

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(4..=8);

let difference = set1.difference(&set2);

assert_eq!(difference.len(), 3);
source

pub fn symmetric_difference<T: SetOps>(&self, other: &T) -> Self

Returns the symmetric difference of the set with another set.

§Arguments
  • other - A reference to another data structure implementing Contains and Into<Set>.
§Returns

Returns a new Set containing elements present in either set but not in both.

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

let set1 = Set::from_iter(1..=5);
let set2 = Set::from_iter(4..=8);

let symmetric_difference = set1.symmetric_difference(&set2);

assert_eq!(symmetric_difference.len(), 6);

Trait Implementations§

source§

impl<'a> BitAnd<&'a HashSet<usize>> for &'a Set

Performs the intersection operation between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let intersection = &set & &hashset;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &'a HashSet<usize>) -> Set

Performs the & operation. Read more
source§

impl BitAnd<&HashSet<usize>> for Set

Performs the intersection operation between an owned Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let intersection = set & &hashset;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &HashSet<usize>) -> Set

Performs the & operation. Read more
source§

impl BitAnd<&Set> for Set

Performs the intersection operation between an owned Set and a reference to Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let intersection = set1 & &set2;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &Set) -> Set

Performs the & operation. Read more
source§

impl<'a> BitAnd<HashSet<usize>> for &'a Set

Performs the intersection operation between a reference to Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let intersection = &set & hashset;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: HashSet<usize>) -> Set

Performs the & operation. Read more
source§

impl BitAnd<HashSet<usize>> for Set

Performs the intersection operation between an owned Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let intersection = set & hashset;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: HashSet<usize>) -> Set

Performs the & operation. Read more
source§

impl<'a> BitAnd<Set> for &'a Set

Performs the intersection operation between a reference to Set and an owned Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let intersection = &set1 & set2;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Set) -> Set

Performs the & operation. Read more
source§

impl<'a> BitAnd for &'a Set

Performs the intersection operation between two references to Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let intersection = &set1 & &set2;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: &'a Set) -> Set

Performs the & operation. Read more
source§

impl BitAnd for Set

Performs the intersection operation between two owned Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let intersection = set1 & set2;
assert_eq!(intersection, Set::from_iter(3..5));
§

type Output = Set

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Set) -> Set

Performs the & operation. Read more
source§

impl<'a> BitAndAssign<&'a HashSet<usize>> for Set

Performs the intersection assignment operation between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let mut set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
set &= &hashset;
assert_eq!(set, Set::from_iter(3..5));
source§

fn bitand_assign(&mut self, rhs: &'a HashSet<usize>)

Performs the &= operation. Read more
source§

impl<'a> BitAndAssign<&'a Set> for Set

Performs the intersection assignment operation between two Set references.

§Examples

use fastset::Set;
let mut set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
set1 &= &set2;
assert_eq!(set1, Set::from_iter(3..5));
source§

fn bitand_assign(&mut self, rhs: &'a Set)

Performs the &= operation. Read more
source§

impl<'a> BitOr<&'a HashSet<usize>> for &'a Set

Performs the union operation between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset = HashSet::<usize>::from_iter(3..8);
let result = &set | &hashset;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &'a HashSet<usize>) -> Set

Performs the | operation. Read more
source§

impl BitOr<&HashSet<usize>> for Set

Performs the union operation between an owned Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = set | &hashset;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &HashSet<usize>) -> Set

Performs the | operation. Read more
source§

impl BitOr<&Set> for Set

Performs the union operation between an owned Set and a reference to Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = set1 | &set2;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &Set) -> Set

Performs the | operation. Read more
source§

impl<'a> BitOr<HashSet<usize>> for &'a Set

Performs the union operation between a reference to Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = &set | hashset;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: HashSet<usize>) -> Set

Performs the | operation. Read more
source§

impl BitOr<HashSet<usize>> for Set

Performs the union operation between an owned Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = set | hashset;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: HashSet<usize>) -> Set

Performs the | operation. Read more
source§

impl<'a> BitOr<Set> for &'a Set

Performs the union operation between a reference to Set and an owned Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = &set1 | set2;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Set) -> Set

Performs the | operation. Read more
source§

impl<'a> BitOr for &'a Set

Performs the union operation between two references to Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = &set1 | &set2;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: &'a Set) -> Set

Performs the | operation. Read more
source§

impl BitOr for Set

Performs the union operation between two owned Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = set1 | set2;
assert_eq!(result, Set::from_iter(0..8));
§

type Output = Set

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Set) -> Set

Performs the | operation. Read more
source§

impl<'a> BitOrAssign<&'a HashSet<usize>> for Set

Performs the union assignment operation between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let mut set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
set |= &hashset;
assert_eq!(set, Set::from_iter(0..8));
source§

fn bitor_assign(&mut self, rhs: &'a HashSet<usize>)

Performs the |= operation. Read more
source§

impl<'a> BitOrAssign<&'a Set> for Set

Performs the union assignment operation between two references to Set instances.

§Examples

use fastset::Set;
let mut set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
set1 |= &set2;
assert_eq!(set1, Set::from_iter(0..8));
source§

fn bitor_assign(&mut self, rhs: &'a Set)

Performs the |= operation. Read more
source§

impl<'a> BitXor<&'a HashSet<usize>> for &'a Set

Computes the symmetric difference between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let symmetric_difference = &set ^ &hashset;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &'a HashSet<usize>) -> Set

Performs the ^ operation. Read more
source§

impl BitXor<&HashSet<usize>> for Set

Computes the symmetric difference between an owned Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let symmetric_difference = set ^ &hashset;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &HashSet<usize>) -> Set

Performs the ^ operation. Read more
source§

impl BitXor<&Set> for Set

Computes the symmetric difference between an owned Set and a reference to Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let symmetric_difference = set1 ^ &set2;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &Set) -> Set

Performs the ^ operation. Read more
source§

impl<'a> BitXor<HashSet<usize>> for &'a Set

Computes the symmetric difference between a reference to Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let symmetric_difference = &set ^ hashset;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: HashSet<usize>) -> Set

Performs the ^ operation. Read more
source§

impl BitXor<HashSet<usize>> for Set

Computes the symmetric difference between an owned Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let symmetric_difference = set ^ hashset;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: HashSet<usize>) -> Set

Performs the ^ operation. Read more
source§

impl<'a> BitXor<Set> for &'a Set

Computes the symmetric difference between a reference to Set and an owned Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let symmetric_difference = &set1 ^ set2;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: Set) -> Set

Performs the ^ operation. Read more
source§

impl<'a> BitXor for &'a Set

Computes the symmetric difference between two Set references.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let symmetric_difference = &set1 ^ &set2;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: &'a Set) -> Set

Performs the ^ operation. Read more
source§

impl BitXor for Set

Computes the symmetric difference between two owned Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let symmetric_difference = set1 ^ set2;
assert_eq!(symmetric_difference, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
§

type Output = Set

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: Set) -> Set

Performs the ^ operation. Read more
source§

impl<'a> BitXorAssign<&'a HashSet<usize>> for Set

Computes the symmetric difference between a reference to Set and a reference to HashSet<usize> and assigns the result to the left operand.

§Examples

use fastset::Set;
use std::collections::HashSet;
let mut set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
set ^= &hashset;
assert_eq!(set, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
source§

fn bitxor_assign(&mut self, rhs: &'a HashSet<usize>)

Performs the ^= operation. Read more
source§

impl<'a> BitXorAssign<&'a Set> for Set

Computes the symmetric difference between two Set references and assigns the result to the left operand.

§Examples

use fastset::Set;
let mut set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
set1 ^= &set2;
assert_eq!(set1, Set::from_iter(0..3).union(&Set::from_iter(5..8)));
source§

fn bitxor_assign(&mut self, rhs: &'a Set)

Performs the ^= operation. Read more
source§

impl Clone for Set

source§

fn clone(&self) -> Set

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Set

Implements the Debug trait for Set.

§Examples

use fastset::Set;
let set = Set::from_iter(0..5);
println!("{:?}", set);
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Set

Implements the Default trait for Set.

§Examples

use fastset::Set;
let set: Set = Default::default();
source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Set

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Set

Implements the Display trait for Set.

§Examples

use fastset::Set;
let set = Set::from_iter(0..5);
println!("{}", set);
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Extend<&'a usize> for Set

Extends the Set with elements from an iterator over references to usize values.

§Examples

use fastset::Set;

let mut set = Set::new(0);
let values = vec![1, 2, 3];
set.extend(values.iter());

assert!(set.contains(&2));
source§

fn extend<I: IntoIterator<Item = &'a usize>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<usize> for Set

Extends the Set with elements from an iterator over usize values.

§Examples

use fastset::Set;

let mut set = Set::new(0);
set.extend(vec![1, 2, 3]);

assert!(set.contains(&2));
source§

fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> From<&'a [usize]> for Set

Converts a slice of usize into a Set.

§Examples

use fastset::Set;

let items = &[1, 2, 3, 4, 5];
let set = Set::from(items);

assert!(set.contains(&3));
source§

fn from(slice: &'a [usize]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize> From<&[usize; N]> for Set

Converts an array of usize into a Set.

§Examples

use fastset::Set;

let items = &[1, 2, 3, 4, 5];
let set = Set::from(items);

assert!(set.contains(&3));
source§

fn from(array: &[usize; N]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a HashSet<usize>> for Set

Converts a reference to HashSet<usize> into a Set.

§Examples

use std::collections::HashSet;
use fastset::Set;

let mut hash_set = HashSet::new();
hash_set.insert(1);
hash_set.insert(2);
hash_set.insert(3);

let set = Set::from(&hash_set);

assert!(set.contains(&3));
source§

fn from(hashset: &'a HashSet<usize>) -> Self

Converts to this type from the input type.
source§

impl From<HashSet<usize>> for Set

Converts a HashSet<usize> into a Set.

§Examples

use std::collections::HashSet;
use fastset::Set;

let mut hash_set = HashSet::new();
hash_set.insert(1);
hash_set.insert(2);
hash_set.insert(3);

let set = Set::from(hash_set);

assert!(set.contains(&3));
source§

fn from(hashset: HashSet<usize>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<usize>> for Set

Converts a Vec<usize> into a Set.

§Examples

use fastset::Set;

let vec = vec![1, 2, 3, 4, 5];
let set = Set::from(vec);

assert!(set.contains(&3));
source§

fn from(vec: Vec<usize>) -> Self

Converts to this type from the input type.
source§

impl<'a> FromIterator<&'a usize> for Set

Converts an iterator over references to usize values into a Set.

§Examples

use fastset::Set;

let values = vec![1, 2, 3];
let set: Set = values.iter().collect();

assert!(set.contains(&2));
source§

fn from_iter<I: IntoIterator<Item = &'a usize>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<usize> for Set

Converts an iterator over usize values into a Set.

§Examples

use fastset::Set;

let set: Set = (1..=5).collect();

assert!(set.contains(&3));
source§

fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Set

Implements the Hash trait for Set.

§Examples

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use fastset::Set;

let set = Set::from_iter(1..=5);

let mut hasher = DefaultHasher::new();
set.hash(&mut hasher);
let hash = hasher.finish();

println!("Hash value of the set: {}", hash);
source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> IntoIterator for &'a Set

Borrows the Set, returning an iterator over references to usize values.

§Examples

use fastset::Set;

let set = Set::from(vec![1, 2, 3]);

for &value in &set {
    println!("{}", value);
}
§

type Item = &'a usize

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, usize>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Set

Mutably borrows the Set, returning an iterator over mutable references to usize values.

§Examples

use fastset::Set;

let mut set = Set::from(vec![1, 2, 3]);

for value in &mut set {
    *value += 1;
}
§

type Item = &'a mut usize

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, usize>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Set

Consumes the Set, returning an iterator over owned usize values.

§Examples

use fastset::Set;

let set = Set::from(vec![1, 2, 3]);
let mut iter = set.into_iter();

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);
§

type Item = usize

The type of the elements being iterated over.
§

type IntoIter = IntoIter<usize>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<HashSet<usize>> for Set

Implements the PartialEq trait for Set with HashSet<usize>.

§Examples

use std::collections::HashSet;
use fastset::Set;
let set = Set::from_iter(0..5);
let hash_set: HashSet<usize> = (0..5).collect();
assert_eq!(set, hash_set);
source§

fn eq(&self, other: &HashSet<usize>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Set

Implements the PartialEq trait for Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(0..5);
assert_eq!(set1, set2);
source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Set

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SetOps for Set

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;
use fastset::SetOps;

let mut set = Set::new(1);
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 fastset::Set;
use fastset::SetOps;

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

let mut iter = set.iter();
assert_eq!(iter.next(), Some(&42));
assert_eq!(iter.next(), Some(&100));
assert_eq!(iter.next(), None);
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, SetOps};

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

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

impl<'a> Sub<&'a HashSet<usize>> for &'a Set

Performs the subtraction operation between a reference to Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = &set - &hashset;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &'a HashSet<usize>) -> Set

Performs the - operation. Read more
source§

impl Sub<&HashSet<usize>> for Set

Performs the subtraction operation between an owned Set and a reference to HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = set - &hashset;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &HashSet<usize>) -> Set

Performs the - operation. Read more
source§

impl Sub<&Set> for Set

Performs the subtraction operation between an owned Set and a reference to Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = set1 - &set2;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Set) -> Set

Performs the - operation. Read more
source§

impl<'a> Sub<HashSet<usize>> for &'a Set

Performs the subtraction operation between a reference to Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = &set - hashset;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: HashSet<usize>) -> Set

Performs the - operation. Read more
source§

impl Sub<HashSet<usize>> for Set

Performs the subtraction operation between an owned Set and an owned HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
let result = set - hashset;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: HashSet<usize>) -> Set

Performs the - operation. Read more
source§

impl<'a> Sub<Set> for &'a Set

Performs the subtraction operation between a reference to Set and an owned Set.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = &set1 - set2;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Set) -> Set

Performs the - operation. Read more
source§

impl<'a> Sub for &'a Set

Performs the subtraction operation between two Set references.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = &set1 - &set2;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &'a Set) -> Set

Performs the - operation. Read more
source§

impl Sub for Set

Performs the subtraction operation between two owned Set instances.

§Examples

use fastset::Set;
let set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
let result = set1 - set2;
assert_eq!(result, Set::from_iter(0..3));
§

type Output = Set

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Set) -> Set

Performs the - operation. Read more
source§

impl<'a> SubAssign<&'a HashSet<usize>> for Set

Performs the subtraction assignment operation between a Set reference and a HashSet<usize>.

§Examples

use fastset::Set;
use std::collections::HashSet;
let mut set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
set -= &hashset;
assert_eq!(set, Set::from_iter(0..3));
source§

fn sub_assign(&mut self, rhs: &'a HashSet<usize>)

Performs the -= operation. Read more
source§

impl<'a> SubAssign<&'a Set> for Set

Performs the subtraction assignment operation between a Set reference and another Set.

§Examples

use fastset::Set;
let mut set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
set1 -= &set2;
assert_eq!(set1, Set::from_iter(0..3));
source§

fn sub_assign(&mut self, rhs: &'a Set)

Performs the -= operation. Read more
source§

impl SubAssign<HashSet<usize>> for Set

Performs the subtraction assignment operation between a Set and a HashSet<usize> reference.

§Examples

use fastset::Set;
use std::collections::HashSet;
let mut set = Set::from_iter(0..5);
let hashset: HashSet<usize> = (3..8).collect();
set -= hashset;
assert_eq!(set, Set::from_iter(0..3));
source§

fn sub_assign(&mut self, rhs: HashSet<usize>)

Performs the -= operation. Read more
source§

impl SubAssign for Set

Performs the subtraction assignment operation between a Set and another Set reference.

§Examples

use fastset::Set;
let mut set1 = Set::from_iter(0..5);
let set2 = Set::from_iter(3..8);
set1 -= set2;
assert_eq!(set1, Set::from_iter(0..3));
source§

fn sub_assign(&mut self, rhs: Set)

Performs the -= operation. Read more
source§

impl Eq for Set

Implements equality comparison for Set.

Two sets are considered equal if they contain the same elements, irrespective of their order.

§Example

let set1 = Set::from(vec![1, 2, 3]);
let set2 = Set::from(vec![3, 2, 1]);

assert_eq!(set1, set2);

Auto Trait Implementations§

§

impl Freeze for Set

§

impl RefUnwindSafe for Set

§

impl Send for Set

§

impl Sync for Set

§

impl Unpin for Set

§

impl UnwindSafe for Set

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,