pub struct Set { /* private fields */ }
Expand description
Represents a custom Set implementation.
Implementations§
source§impl Set
impl Set
sourcepub fn with_capacity(capacity: usize) -> Self
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);
sourcepub fn capacity(&self) -> usize
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);
sourcepub fn reserve(&mut self, new_max_element: usize)
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);
sourcepub fn shrink_to(&mut self, min_capacity: usize)
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);
sourcepub fn shrink_to_fit(&mut self)
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);
sourcepub fn len(&self) -> usize
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);
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn iter(&self) -> Iter<'_, usize>
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);
}
sourcepub fn clear(&mut self)
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());
sourcepub fn insert(&mut self, value: usize) -> bool
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));
sourcepub fn remove(&mut self, value: &usize) -> bool
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));
sourcepub fn contains(&self, value: &usize) -> bool
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));
sourcepub fn get(&self, value: &usize) -> Option<usize>
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);
sourcepub fn take(&mut self, value: &usize) -> Option<usize>
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);
sourcepub fn max(&self) -> Option<usize>
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));
sourcepub fn min(&self) -> Option<usize>
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));
sourcepub fn range_cardinality<R>(&self, range: R) -> usizewhere
R: RangeBounds<usize>,
pub fn range_cardinality<R>(&self, range: R) -> usizewhere
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);
sourcepub fn rank(&self, value: usize) -> usize
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);
sourcepub fn remove_largest(&mut self) -> Option<usize>
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);
sourcepub fn remove_smallest(&mut self) -> Option<usize>
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);
sourcepub fn random(&self, rng: &mut WyRand) -> Option<usize>
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 theRng
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());
sourcepub fn insert_unchecked(&mut self, value: usize) -> bool
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:
value
must be within the bounds of theindicator
vector (respect the declaredmax_element
during construction) avoiding out-of-bounds pointer arithmetic.- There are no concurrent mutable references to
indicator
,index
, orelements
, 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);
}
sourcepub fn remove_unchecked(&mut self, value: &usize) -> bool
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:
value
must be within the bounds of theindicator
vector, avoiding out-of-bounds pointer arithmetic.- There are no concurrent mutable references to
indicator
,index
, orelements
, 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
impl Set
sourcepub fn is_subset<T: SetOps>(&self, other: &T) -> bool
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 implementingContains
andInto<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));
sourcepub fn is_superset<T: SetOps>(&self, other: &T) -> bool
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 implementingContains
andInto<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));
sourcepub fn is_disjoint<T: SetOps>(&self, other: &T) -> bool
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 implementingContains
andInto<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));
sourcepub fn union<T: SetOps>(&self, other: &T) -> Self
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 implementingContains
andInto<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);
sourcepub fn intersection<T: SetOps>(&self, other: &T) -> Self
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 implementingContains
andInto<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);
sourcepub fn difference<T: SetOps>(&self, other: &T) -> Self
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 implementingContains
andInto<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);
sourcepub fn symmetric_difference<T: SetOps>(&self, other: &T) -> Self
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 implementingContains
andInto<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
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));
source§impl BitAnd<&HashSet<usize>> for Set
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));
source§impl BitAnd<&Set> for Set
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));
source§impl<'a> BitAnd<HashSet<usize>> for &'a Set
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));
source§impl BitAnd<HashSet<usize>> for Set
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));
source§impl<'a> BitAnd<Set> for &'a Set
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));
source§impl<'a> BitAnd for &'a Set
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));
source§impl BitAnd for Set
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));
source§impl<'a> BitAndAssign<&'a HashSet<usize>> for Set
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§impl<'a> BitAndAssign<&'a Set> for Set
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)
fn bitand_assign(&mut self, rhs: &'a Set)
&=
operation. Read moresource§impl<'a> BitOr<&'a HashSet<usize>> for &'a Set
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));
source§impl BitOr<&HashSet<usize>> for Set
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));
source§impl BitOr<&Set> for Set
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));
source§impl<'a> BitOr<HashSet<usize>> for &'a Set
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));
source§impl BitOr<HashSet<usize>> for Set
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));
source§impl<'a> BitOr<Set> for &'a Set
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));
source§impl<'a> BitOr for &'a Set
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));
source§impl BitOr for Set
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));
source§impl<'a> BitOrAssign<&'a HashSet<usize>> for Set
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§impl<'a> BitOrAssign<&'a Set> for Set
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)
fn bitor_assign(&mut self, rhs: &'a Set)
|=
operation. Read moresource§impl<'a> BitXor<&'a HashSet<usize>> for &'a Set
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)));
source§impl BitXor<&HashSet<usize>> for Set
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)));
source§impl BitXor<&Set> for Set
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)));
source§impl<'a> BitXor<HashSet<usize>> for &'a Set
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)));
source§impl BitXor<HashSet<usize>> for Set
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)));
source§impl<'a> BitXor<Set> for &'a Set
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)));
source§impl<'a> BitXor for &'a Set
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)));
source§impl BitXor for Set
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)));
source§impl<'a> BitXorAssign<&'a HashSet<usize>> for Set
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§impl<'a> BitXorAssign<&'a Set> for Set
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)
fn bitxor_assign(&mut self, rhs: &'a Set)
^=
operation. Read moresource§impl Debug for Set
impl Debug for Set
Implements the Debug
trait for Set
.
§Examples
use fastset::Set;
let set = Set::from_iter(0..5);
println!("{:?}", set);
source§impl Default for Set
impl Default for Set
Implements the Default
trait for Set
.
§Examples
use fastset::Set;
let set: Set = Default::default();
source§impl<'de> Deserialize<'de> for Set
impl<'de> Deserialize<'de> for Set
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Set
impl Display for Set
Implements the Display
trait for Set
.
§Examples
use fastset::Set;
let set = Set::from_iter(0..5);
println!("{}", set);
source§impl<'a> Extend<&'a usize> for Set
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)
fn extend<I: IntoIterator<Item = &'a usize>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<usize> for Set
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)
fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a> From<&'a [usize]> for Set
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§impl<const N: usize> From<&[usize; N]> for Set
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§impl<'a> From<&'a HashSet<usize>> for Set
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§impl From<HashSet<usize>> for Set
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§impl From<Vec<usize>> for Set
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§impl<'a> FromIterator<&'a usize> for Set
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§impl FromIterator<usize> for Set
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§impl Hash for Set
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§impl<'a> IntoIterator for &'a Set
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);
}
source§impl<'a> IntoIterator for &'a mut Set
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;
}
source§impl IntoIterator for Set
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);
source§impl PartialEq<HashSet<usize>> for Set
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§impl PartialEq for Set
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§impl SetOps for Set
impl SetOps for Set
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 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> + '_>
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§impl<'a> Sub<&'a HashSet<usize>> for &'a Set
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));
source§impl Sub<&HashSet<usize>> for Set
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));
source§impl Sub<&Set> for Set
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));
source§impl<'a> Sub<HashSet<usize>> for &'a Set
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));
source§impl Sub<HashSet<usize>> for Set
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));
source§impl<'a> Sub<Set> for &'a Set
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));
source§impl<'a> Sub for &'a Set
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));
source§impl Sub for Set
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));
source§impl<'a> SubAssign<&'a HashSet<usize>> for Set
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§impl<'a> SubAssign<&'a Set> for Set
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)
fn sub_assign(&mut self, rhs: &'a Set)
-=
operation. Read moresource§impl SubAssign<HashSet<usize>> for Set
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§impl SubAssign for Set
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)
fn sub_assign(&mut self, rhs: Set)
-=
operation. Read moreimpl 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);