pub struct USizeSet { /* private fields */ }
Expand description
A set of usize
that is implemented as a bit vector. Each usize
that is
in the range of possible elements is represented by one bit in a vector of
numbers. This generally has better performance than a HashSet
.
Implementations§
Source§impl USizeSet
impl USizeSet
Sourcepub fn new(min: usize, max: usize) -> USizeSetResult<USizeSet>
pub fn new(min: usize, max: usize) -> USizeSetResult<USizeSet>
Creates a new, empty USizeSet
with the given (inclusive) bounds.
§Arguments
min
: The minimum value that can be contained in the created set. Any values lower than that will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be less than or equal tomax
.max
: The maximum value that can be contained in the created set. Any values higher than that will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be greater than or equal tomin
.
§Errors
If min > max
. In that case, a USizeSetError::InvalidBounds
is
returned.
Sourcepub fn singleton(
min: usize,
max: usize,
content: usize,
) -> USizeSetResult<USizeSet>
pub fn singleton( min: usize, max: usize, content: usize, ) -> USizeSetResult<USizeSet>
Creates a new singleton USizeSet
with the given (inclusive) bounds.
The set contains one element, which is specified by content
.
§Arguments
min
: The minimum value that can be contained in the created set. Any values lower than that will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be less than or equal tomax
.max
: The maximum value that can be contained in the created set. Any values higher than that will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be greater than or equal tomin
.content
: The only element contained by the created set. Must be within the bounds.
§Errors
USizeSetError::InvalidBounds
: Ifmin > max
.USizeSetError::OutOfBounds
: Ifcontent < min
orcontent > max
.
Sourcepub fn range(min: usize, max: usize) -> USizeSetResult<USizeSet>
pub fn range(min: usize, max: usize) -> USizeSetResult<USizeSet>
Creates a new USizeSet
that includes all numbers in the given
(inclusive) bounds. Note that these bounds also apply later.
§Arguments
min
: The minimum value contained in the created set, which is also the minimum that can be contained. Any values lower than this will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be less than or equal tomax
.max
: The maximum value contained in the created set, which is also the maximum value that can be contained. Any values higher than this will yield aUSizeSetError::OutOfBounds
if inserted or removed. Must be greater than or equal tomin
.
§Errors
If min > max
. In that case, a USizeSetError::InvalidBounds
is
returned.
Sourcepub fn contains(&self, number: usize) -> bool
pub fn contains(&self, number: usize) -> bool
Indicates whether this set contains the given number, in which case
this method returns true
. If it is not contained or outside the
bounds, false
will be returned.
Sourcepub fn insert(&mut self, number: usize) -> USizeSetResult<bool>
pub fn insert(&mut self, number: usize) -> USizeSetResult<bool>
Inserts the given number into this set, such that USizeSet::contains
returns true
for this number afterwards. Note that it must be within
the bounds provided at construction time.
This method returns true
if the set has changed (i.e. the number was
not present before) and false
otherwise.
§Errors
If number
is less than USizeSet::min or greater than
USizeSet::max. In that case, USizeSetError::OutOfBounds
is
returned.
Sourcepub fn remove(&mut self, number: usize) -> USizeSetResult<bool>
pub fn remove(&mut self, number: usize) -> USizeSetResult<bool>
Removes the given number from this set, such that USizeSet::contains
returns false
for this number afterwards. Note that it must be within
the bounds provided at construction time.
This method returns true
if the set has changed (i.e. the number was
present before) and false
otherwise.
§Errors
If number
is less than USizeSet::min or greater than
USizeSet::max. In that case, USizeSetError::OutOfBounds
is
returned.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all numbers from this set, such that USizeSet::contains will
return false
for all inputs and USizeSet::is_empty will return
true
.
Sourcepub fn iter(&self) -> USizeSetIter<'_> ⓘ
pub fn iter(&self) -> USizeSetIter<'_> ⓘ
Returns an iterator over the numbers contained in this set in ascending order.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Indicates whether this set is empty, i.e. contains no numbers. If this
method returns true
, USizeSet::contains will return false
for all
inputs.
Sourcepub fn union_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
pub fn union_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
Computes the set union between this and the given set and stores the
result in this set. The bounds of this set and other
must be equal.
USizeSet
implements BitOrAssign as syntactic sugar for this
operation. Note that that implementation panics instead of returning
potential errors.
§Returns
True, if and only if this set changed as a result of the operation.
§Errors
If either the minimum or maximum of this set and other
are different.
In that case, USizeError::DifferentBounds
is returned.
Sourcepub fn union(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
pub fn union(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
Computes the set union between this and the given set and stores the
result in a new set which is returned. The bounds of this set and
other
must be equal.
USizeSet
implements BitOr as syntactic sugar for this operation.
Note that that implementation panics instead of returning potential
errors.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn intersect_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
pub fn intersect_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
Computes the set intersection between this and the given set and stores
the result in this set. The bounds of this set and other
must be
equal.
USizeSet
implements BitAndAssign as syntactic sugar for this
operation. Note that that implementation panics instead of returning
potential errors.
§Returns
True, if and only if this set changed as a result of the operation.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn intersect(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
pub fn intersect(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
Computes the set intersection between this and the given set and stores
the result in a new set which is returned. The bounds of this set and
other
must be equal.
USizeSet
implements BitAnd as syntactic sugar for this operation.
Note that that implementation panics instead of returning potential
errors.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn difference_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
pub fn difference_assign(&mut self, other: &USizeSet) -> USizeSetResult<bool>
Computes the set difference between this and the given set and stores
the result in this set. The bounds of this set and other
must be
equal. other
acts as the right-hand-side, meaning its elements are
removed from the result.
USizeSet
implements SubAssign as syntactic sugar for this
operation. Note that that implementation panics instead of returning
potential errors.
§Returns
True, if and only if this set changed as a result of the operation.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn difference(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
pub fn difference(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
Computes the set difference between this and the given set and stores
the result in a new set which is returned. The bounds of this set and
other
must be equal.
USizeSet
implements Sub as syntactic sugar for this operation. Note
that that implementation panics instead of returning potential errors.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn symmetric_difference_assign(
&mut self,
other: &USizeSet,
) -> USizeSetResult<bool>
pub fn symmetric_difference_assign( &mut self, other: &USizeSet, ) -> USizeSetResult<bool>
Computes the symmetric set difference between this and the given set
and stores the result in this set. The bounds of this set and other
must be equal.
USizeSet
implements BitXorAssign as syntactic sugar for this
operation. Note that that implementation panics instead of returning
potential errors.
§Returns
True, if and only if this set changed as a result of the operation.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Sourcepub fn symmetric_difference(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
pub fn symmetric_difference(&self, other: &USizeSet) -> USizeSetResult<USizeSet>
Computes the symmetric set difference between this and the given set
and stores the result in a new set which is returned. The bounds of
this set and other
must be equal.
USizeSet
implements BitXor as syntactic sugar for this operation.
Note that that implementation panics instead of returning potential
errors.
§Errors
If the minimum or maximum of this set and other
are different. In
that case, USizeError::DifferentBounds
is returned.
Trait Implementations§
Source§impl BitAndAssign<&USizeSet> for &mut USizeSet
impl BitAndAssign<&USizeSet> for &mut USizeSet
Source§fn bitand_assign(&mut self, rhs: &USizeSet)
fn bitand_assign(&mut self, rhs: &USizeSet)
&=
operation. Read moreSource§impl BitAndAssign<&USizeSet> for USizeSet
impl BitAndAssign<&USizeSet> for USizeSet
Source§fn bitand_assign(&mut self, rhs: &USizeSet)
fn bitand_assign(&mut self, rhs: &USizeSet)
&=
operation. Read moreSource§impl BitOrAssign<&USizeSet> for &mut USizeSet
impl BitOrAssign<&USizeSet> for &mut USizeSet
Source§fn bitor_assign(&mut self, rhs: &USizeSet)
fn bitor_assign(&mut self, rhs: &USizeSet)
|=
operation. Read moreSource§impl BitOrAssign<&USizeSet> for USizeSet
impl BitOrAssign<&USizeSet> for USizeSet
Source§fn bitor_assign(&mut self, rhs: &USizeSet)
fn bitor_assign(&mut self, rhs: &USizeSet)
|=
operation. Read moreSource§impl BitXorAssign<&USizeSet> for &mut USizeSet
impl BitXorAssign<&USizeSet> for &mut USizeSet
Source§fn bitxor_assign(&mut self, rhs: &USizeSet)
fn bitxor_assign(&mut self, rhs: &USizeSet)
^=
operation. Read moreSource§impl BitXorAssign<&USizeSet> for USizeSet
impl BitXorAssign<&USizeSet> for USizeSet
Source§fn bitxor_assign(&mut self, rhs: &USizeSet)
fn bitxor_assign(&mut self, rhs: &USizeSet)
^=
operation. Read moreSource§impl SubAssign<&USizeSet> for &mut USizeSet
impl SubAssign<&USizeSet> for &mut USizeSet
Source§fn sub_assign(&mut self, rhs: &USizeSet)
fn sub_assign(&mut self, rhs: &USizeSet)
-=
operation. Read moreSource§impl SubAssign<&USizeSet> for USizeSet
impl SubAssign<&USizeSet> for USizeSet
Source§fn sub_assign(&mut self, rhs: &USizeSet)
fn sub_assign(&mut self, rhs: &USizeSet)
-=
operation. Read more