Struct regex_syntax::hir::interval::IntervalSet

source ·
pub struct IntervalSet<I> {
    ranges: Vec<I>,
    folded: bool,
}

Fields§

§ranges: Vec<I>

A sorted set of non-overlapping ranges.

§folded: bool

While not required at all for correctness, we keep track of whether an interval set has been case folded or not. This helps us avoid doing redundant work if, for example, a set has already been cased folded. And note that whether a set is folded or not is preserved through all of the pairwise set operations. That is, if both interval sets have been case folded, then any of difference, union, intersection or symmetric difference all produce a case folded set.

Note that when this is true, it must be the case that the set is case folded. But when it’s false, the set may be case folded. In other words, we only set this to true when we know it to be case, but we’re okay with it being false if it would otherwise be costly to determine whether it should be true. This means code cannot assume that a false value necessarily indicates that the set is not case folded.

Bottom line: this is a performance optimization.

Implementations§

source§

impl<I: Interval> IntervalSet<I>

source

pub fn new<T: IntoIterator<Item = I>>(intervals: T) -> IntervalSet<I>

Create a new set from a sequence of intervals. Each interval is specified as a pair of bounds, where both bounds are inclusive.

The given ranges do not need to be in any specific order, and ranges may overlap.

source

pub fn push(&mut self, interval: I)

Add a new interval to this set.

source

pub fn iter(&self) -> IntervalSetIter<'_, I>

Return an iterator over all intervals in this set.

The iterator yields intervals in ascending order.

source

pub fn intervals(&self) -> &[I]

Return an immutable slice of intervals in this set.

The sequence returned is in canonical ordering.

source

pub fn case_fold_simple(&mut self) -> Result<(), CaseFoldError>

Expand this interval set such that it contains all case folded characters. For example, if this class consists of the range a-z, then applying case folding will result in the class containing both the ranges a-z and A-Z.

This returns an error if the necessary case mapping data is not available.

source

pub fn union(&mut self, other: &IntervalSet<I>)

Union this set with the given set, in place.

source

pub fn intersect(&mut self, other: &IntervalSet<I>)

Intersect this set with the given set, in place.

source

pub fn difference(&mut self, other: &IntervalSet<I>)

Subtract the given set from this set, in place.

source

pub fn symmetric_difference(&mut self, other: &IntervalSet<I>)

Compute the symmetric difference of the two sets, in place.

This computes the symmetric difference of two interval sets. This removes all elements in this set that are also in the given set, but also adds all elements from the given set that aren’t in this set. That is, the set will contain all elements in either set, but will not contain any elements that are in both sets.

source

pub fn negate(&mut self)

Negate this interval set.

For all x where x is any element, if x was in this set, then it will not be in this set after negation.

source

fn canonicalize(&mut self)

Converts this set into a canonical ordering.

source

fn is_canonical(&self) -> bool

Returns true if and only if this class is in a canonical ordering.

Trait Implementations§

source§

impl<I: Clone> Clone for IntervalSet<I>

source§

fn clone(&self) -> IntervalSet<I>

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<I: Debug> Debug for IntervalSet<I>

source§

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

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

impl<I: Interval> PartialEq for IntervalSet<I>

source§

fn eq(&self, other: &IntervalSet<I>) -> 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<I: Interval> Eq for IntervalSet<I>

Auto Trait Implementations§

§

impl<I> Freeze for IntervalSet<I>

§

impl<I> RefUnwindSafe for IntervalSet<I>
where I: RefUnwindSafe,

§

impl<I> Send for IntervalSet<I>
where I: Send,

§

impl<I> Sync for IntervalSet<I>
where I: Sync,

§

impl<I> Unpin for IntervalSet<I>
where I: Unpin,

§

impl<I> UnwindSafe for IntervalSet<I>
where I: 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> 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, 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.