pub struct IntSet<T>(/* private fields */);
std
only.Expand description
A fast & efficient invertible ordered set for small (up to 32-bit) unsigned integer types.
Implementations§
Source§impl IntSet<u32>
impl IntSet<u32>
Sourcepub fn from_sparse_bit_set(data: &[u8]) -> Result<IntSet<u32>, DecodingError>
pub fn from_sparse_bit_set(data: &[u8]) -> Result<IntSet<u32>, DecodingError>
Populate this set with the values obtained from decoding the provided sparse bit set bytes.
Sparse bit sets are a specialized, compact encoding of bit sets defined in the IFT specification: https://w3c.github.io/IFT/Overview.html#sparse-bit-set-decoding
Sourcepub fn from_sparse_bit_set_bounded(
data: &[u8],
bias: u32,
max_value: u32,
) -> Result<(IntSet<u32>, &[u8]), DecodingError>
pub fn from_sparse_bit_set_bounded( data: &[u8], bias: u32, max_value: u32, ) -> Result<(IntSet<u32>, &[u8]), DecodingError>
Populate this set with the values obtained from decoding the provided sparse bit set bytes.
During decoding bias will be added to each decoded set members value. The final set will not contain any values larger than max_value: any encoded values larger than max_value after the bias is applied are ignored.
Sparse bit sets are a specialized, compact encoding of bit sets defined in the IFT specification: https://w3c.github.io/IFT/Overview.html#sparse-bit-set-decoding
Sourcepub fn to_sparse_bit_set(&self) -> Vec<u8>
pub fn to_sparse_bit_set(&self) -> Vec<u8>
Encode this set as a sparse bit set byte encoding.
Sparse bit sets are a specialized, compact encoding of bit sets defined in the IFT specification: https://w3c.github.io/IFT/Overview.html#sparse-bit-set-decoding
Source§impl<T: Domain> IntSet<T>
impl<T: Domain> IntSet<T>
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
Returns an iterator over all members of the set in sorted ascending order.
Note: iteration of inverted sets can be extremely slow due to the very large number of members in the set
care should be taken when using .iter()
in combination with an inverted set.
Sourcepub fn inclusive_iter(&self) -> Option<impl DoubleEndedIterator<Item = T> + '_>
pub fn inclusive_iter(&self) -> Option<impl DoubleEndedIterator<Item = T> + '_>
If this is an inclusive membership set then returns an iterator over the members, otherwise returns None
.
Sourcepub fn iter_after(&self, value: T) -> impl Iterator<Item = T> + '_
pub fn iter_after(&self, value: T) -> impl Iterator<Item = T> + '_
Returns an iterator over the members of this set that come after value
in ascending order.
Note: iteration of inverted sets can be extremely slow due to the very large number of members in the set
care should be taken when using .iter()
in combination with an inverted set.
Sourcepub fn iter_ranges(&self) -> impl Iterator<Item = RangeInclusive<T>> + '_
pub fn iter_ranges(&self) -> impl Iterator<Item = RangeInclusive<T>> + '_
Returns an iterator over all disjoint ranges of values within the set in sorted ascending order.
Sourcepub fn iter_excluded_ranges(
&self,
) -> impl Iterator<Item = RangeInclusive<T>> + '_
pub fn iter_excluded_ranges( &self, ) -> impl Iterator<Item = RangeInclusive<T>> + '_
Returns an iterator over all disjoint ranges of values not within the set in sorted ascending order.
Sourcepub fn insert(&mut self, val: T) -> bool
pub fn insert(&mut self, val: T) -> bool
Adds a value to the set.
Returns true
if the value was newly inserted.
Sourcepub fn insert_range(&mut self, range: RangeInclusive<T>)
pub fn insert_range(&mut self, range: RangeInclusive<T>)
Add all values in range as members of this set.
Sourcepub fn extend_unsorted<U: IntoIterator<Item = T>>(&mut self, iter: U)
pub fn extend_unsorted<U: IntoIterator<Item = T>>(&mut self, iter: U)
An alternate version of extend()
which is optimized for inserting an unsorted iterator of values.
Sourcepub fn remove(&mut self, val: T) -> bool
pub fn remove(&mut self, val: T) -> bool
Removes a value from the set. Returns whether the value was present in the set.
pub fn remove_all<U: IntoIterator<Item = T>>(&mut self, iter: U)
Sourcepub fn remove_range(&mut self, range: RangeInclusive<T>)
pub fn remove_range(&mut self, range: RangeInclusive<T>)
Removes all values in range as members of this set.
Sourcepub fn union(&mut self, other: &IntSet<T>)
pub fn union(&mut self, other: &IntSet<T>)
Sets the members of this set to the union of self and other.
Sourcepub fn intersect(&mut self, other: &IntSet<T>)
pub fn intersect(&mut self, other: &IntSet<T>)
Sets the members of this set to the intersection of self and other.
Sourcepub fn intersects_range(&self, range: RangeInclusive<T>) -> bool
pub fn intersects_range(&self, range: RangeInclusive<T>) -> bool
Returns true if this set contains at least one element in ‘range’.
Sourcepub fn intersects_set(&self, other: &IntSet<T>) -> bool
pub fn intersects_set(&self, other: &IntSet<T>) -> bool
Returns true if this set contains at least one element in ‘other’.
Sourcepub fn first(&self) -> Option<T>
pub fn first(&self) -> Option<T>
Returns first element in the set, if any. This element is always the minimum of all elements in the set.
Trait Implementations§
Source§impl<T: Domain> Extend<T> for IntSet<T>
impl<T: Domain> Extend<T> for IntSet<T>
Source§fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)
fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)
Extends a collection with the contents of an iterator.
This implementation is optimized to provide the best performance when the iterator contains sorted values.
Consider using extend_unsorted()
if the iterator is known to contain unsorted values.
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
)