pub struct IsizeCOSet { /* private fields */ }Expand description
Immutable canonical interval set.
Internally this is an Arc<[IsizeCO]>, so cloning a IsizeCOSet is cheap.
Canonical invariant:
for every adjacent pair a, b:
a.end_excl() < b.start()The strict < means both overlap and adjacency have already been merged.
Implementations§
Source§impl IsizeCOSet
impl IsizeCOSet
Sourcepub fn interval_count(&self) -> usize
pub fn interval_count(&self) -> usize
Returns the number of canonical intervals.
For the IsizeCO domain, the maximum canonical interval count is 128,
e.g. alternating single-point intervals across [isize::MIN, isize::MAX).
Sourcepub fn as_slice(&self) -> &[IsizeCO]
pub fn as_slice(&self) -> &[IsizeCO]
Returns the canonical interval slice.
The returned slice is sorted, non-overlapping, and contains no adjacent intervals.
Sourcepub fn iter_intervals(&self) -> impl Iterator<Item = IsizeCO>
pub fn iter_intervals(&self) -> impl Iterator<Item = IsizeCO>
Iterates over canonical intervals by value.
Source§impl IsizeCOSet
impl IsizeCOSet
Sourcepub fn contains_point(&self, x: isize) -> bool
pub fn contains_point(&self, x: isize) -> bool
Returns whether x is covered by any interval in the set.
Complexity: O(log n).
Sourcepub fn contains_interval(&self, query: IsizeCO) -> bool
pub fn contains_interval(&self, query: IsizeCO) -> bool
Returns whether query is fully contained by one interval.
Since the set is canonical, a contained query interval can only
be contained by the interval immediately preceding or starting
at query.start().
Complexity: O(log n).
Sourcepub fn intersects_interval(&self, query: IsizeCO) -> bool
pub fn intersects_interval(&self, query: IsizeCO) -> bool
Returns whether query intersects any interval in the set.
Complexity: O(log n).
Source§impl IsizeCOSet
impl IsizeCOSet
Sourcepub fn interval_containing_point(&self, x: isize) -> Option<IsizeCO>
pub fn interval_containing_point(&self, x: isize) -> Option<IsizeCO>
Returns the unique interval containing x, if any.
Because the set is canonical, at most one interval can contain a single point.
Complexity: O(log n).
Source§impl IsizeCOSet
impl IsizeCOSet
Sourcepub fn intervals_intersecting(
&self,
query: IsizeCO,
) -> impl Iterator<Item = IsizeCO>
pub fn intervals_intersecting( &self, query: IsizeCO, ) -> impl Iterator<Item = IsizeCO>
Iterates over all canonical intervals intersecting query.
The iterator yields original intervals stored in the set, not clipped intersection segments.
Complexity: O(log n + k), where k is the number of
returned intervals.
Sourcepub fn intersections(&self, query: IsizeCO) -> impl Iterator<Item = IsizeCO>
pub fn intersections(&self, query: IsizeCO) -> impl Iterator<Item = IsizeCO>
Iterates over clipped intersection segments with query.
Example:
set: [10, 20), [30, 40)
query: [15, 35)
out: [15, 20), [30, 35)Complexity: O(log n + k), where k is the number of
intersecting intervals.
Source§impl IsizeCOSet
impl IsizeCOSet
Sourcepub fn covered_len(&self, query: IsizeCO) -> usize
pub fn covered_len(&self, query: IsizeCO) -> usize
Returns the covered length inside query.
Since IsizeCOSet is canonical, all intersection segments are
disjoint, so summing their lengths is valid.
The result is always <= query.len().
Sourcepub fn uncovered_len(&self, query: IsizeCO) -> usize
pub fn uncovered_len(&self, query: IsizeCO) -> usize
Returns the uncovered length inside query.
Sourcepub fn coverage_ratio(&self, query: IsizeCO) -> f32
pub fn coverage_ratio(&self, query: IsizeCO) -> f32
Returns covered_len(query) / query.len() as f32.
query.len() is non-zero because IsizeCO cannot represent an
empty interval.
Trait Implementations§
Source§impl Clone for IsizeCOSet
impl Clone for IsizeCOSet
Source§fn clone(&self) -> IsizeCOSet
fn clone(&self) -> IsizeCOSet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IsizeCOSet
impl Debug for IsizeCOSet
Source§impl PartialEq for IsizeCOSet
impl PartialEq for IsizeCOSet
Source§fn eq(&self, other: &IsizeCOSet) -> bool
fn eq(&self, other: &IsizeCOSet) -> bool
self and other values to be equal, and is used by ==.