pub struct U64COSet { /* private fields */ }Expand description
Immutable canonical interval set.
Internally this is an Arc<[U64CO]>, so cloning a U64COSet 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 U64COSet
impl U64COSet
Sourcepub fn interval_count(&self) -> u64
pub fn interval_count(&self) -> u64
Returns the number of canonical intervals.
For the U64CO domain, the maximum canonical interval count is
128, e.g. [0, 1), [2, 3), ..., [254, 255).
Sourcepub fn as_slice(&self) -> &[U64CO]
pub fn as_slice(&self) -> &[U64CO]
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 = U64CO>
pub fn iter_intervals(&self) -> impl Iterator<Item = U64CO>
Iterates over canonical intervals by value.
Source§impl U64COSet
impl U64COSet
Sourcepub fn contains_point(&self, x: u64) -> bool
pub fn contains_point(&self, x: u64) -> bool
Returns whether x is covered by any interval in the set.
Complexity: O(log n).
Sourcepub fn contains_interval(&self, query: U64CO) -> bool
pub fn contains_interval(&self, query: U64CO) -> 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: U64CO) -> bool
pub fn intersects_interval(&self, query: U64CO) -> bool
Returns whether query intersects any interval in the set.
Complexity: O(log n).
Source§impl U64COSet
impl U64COSet
Sourcepub fn interval_containing_point(&self, x: u64) -> Option<U64CO>
pub fn interval_containing_point(&self, x: u64) -> Option<U64CO>
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 U64COSet
impl U64COSet
Sourcepub fn intervals_intersecting(
&self,
query: U64CO,
) -> impl Iterator<Item = U64CO>
pub fn intervals_intersecting( &self, query: U64CO, ) -> impl Iterator<Item = U64CO>
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: U64CO) -> impl Iterator<Item = U64CO>
pub fn intersections(&self, query: U64CO) -> impl Iterator<Item = U64CO>
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 U64COSet
impl U64COSet
Sourcepub fn covered_len(&self, query: U64CO) -> u64
pub fn covered_len(&self, query: U64CO) -> u64
Returns the covered length inside query.
Since U64COSet 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: U64CO) -> u64
pub fn uncovered_len(&self, query: U64CO) -> u64
Returns the uncovered length inside query.
Sourcepub fn coverage_ratio(&self, query: U64CO) -> f32
pub fn coverage_ratio(&self, query: U64CO) -> f32
Returns covered_len(query) / query.len() as f32.
query.len() is non-zero because U64CO cannot represent an
empty interval.