read_fonts::collections::int_set

Struct IntSet

source
pub struct IntSet<T>(/* private fields */);
Expand description

A fast & efficient invertible ordered set for small (up to 32-bit) unsigned integer types.

Implementations§

source§

impl IntSet<u32>

source

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

source

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

source

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>

source

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.

source

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.

source

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.

source

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.

source

pub fn insert(&mut self, val: T) -> bool

Adds a value to the set.

Returns true if the value was newly inserted.

source

pub fn insert_range(&mut self, range: RangeInclusive<T>)

Add all values in range as members of this set.

source

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.

source

pub fn remove(&mut self, val: T) -> bool

Removes a value from the set. Returns whether the value was present in the set.

source

pub fn remove_all<U: IntoIterator<Item = T>>(&mut self, iter: U)

source

pub fn remove_range(&mut self, range: RangeInclusive<T>)

Removes all values in range as members of this set.

source

pub fn union(&mut self, other: &IntSet<T>)

Sets the members of this set to the union of self and other.

source

pub fn intersect(&mut self, other: &IntSet<T>)

Sets the members of this set to the intersection of self and other.

source

pub fn intersects_range(&self, range: RangeInclusive<T>) -> bool

Returns true if this set contains at least one element in ‘range’.

source

pub fn intersects_set(&self, other: &IntSet<T>) -> bool

Returns true if this set contains at least one element in ‘other’.

source

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.

source

pub fn last(&self) -> Option<T>

Returns the last element in the set, if any. This element is always the maximum of all elements in the set.

source

pub fn contains(&self, val: T) -> bool

Returns true if the set contains a value.

source

pub fn len(&self) -> u64

Returns the number of members in this set.

source

pub fn is_empty(&self) -> bool

Return true if there are no members in this set.

source§

impl<T> IntSet<T>

source

pub fn empty() -> IntSet<T>

Create a new empty set (inclusive).

source

pub fn all() -> IntSet<T>

Create a new set which contains all integers (exclusive).

source

pub fn is_inverted(&self) -> bool

Returns true if this set is inverted (has exclusive membership).

source

pub fn invert(&mut self)

Return the inverted version of this set.

source

pub fn clear(&mut self)

Clears the set, removing all values.

Trait Implementations§

source§

impl<T: Clone> Clone for IntSet<T>

source§

fn clone(&self) -> IntSet<T>

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<T: Debug> Debug for IntSet<T>

source§

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

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

impl<T> Default for IntSet<T>

source§

fn default() -> IntSet<T>

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

impl<T: Domain> Extend<T> for IntSet<T>

source§

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)

🔬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<T: Domain, const N: usize> From<[T; N]> for IntSet<T>

source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
source§

impl<T: Domain> FromIterator<T> for IntSet<T>

source§

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

Creates a value from an iterator. Read more
source§

impl<T: Domain> Hash for IntSet<T>

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<T: Domain + Ord> Ord for IntSet<T>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl<T: Domain> PartialEq for IntSet<T>

source§

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

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

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

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

impl<T: Domain + Ord> PartialOrd for IntSet<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Domain> Eq for IntSet<T>

Auto Trait Implementations§

§

impl<T> !Freeze for IntSet<T>

§

impl<T> !RefUnwindSafe for IntSet<T>

§

impl<T> Send for IntSet<T>
where T: Send,

§

impl<T> !Sync for IntSet<T>

§

impl<T> Unpin for IntSet<T>
where T: Unpin,

§

impl<T> UnwindSafe for IntSet<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

source§

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, U> TryFrom<U> for T
where U: Into<T>,

source§

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>,

source§

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.