pub struct IntCOSet<I: IntCO> { /* private fields */ }Expand description
Immutable canonical closed-open integer interval set.
Internally this is an Arc<[I]>, so cloning an IntCOSet<I> 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.
I::Ord is expected to follow interval boundary ordering, consistent with
the primitive interval implementations provided by int_interval.
Implementations§
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn interval_count(&self) -> usize
pub fn interval_count(&self) -> usize
Returns the number of canonical intervals.
Sourcepub fn as_slice(&self) -> &[I]
pub fn as_slice(&self) -> &[I]
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 = I> + '_
pub fn iter_intervals(&self) -> impl Iterator<Item = I> + '_
Iterates over canonical intervals by value.
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn intersection_with_interval(&self, query: I) -> Self
pub fn intersection_with_interval(&self, query: I) -> Self
Returns the intersection of this set with query.
The returned set contains the clipped segments of all canonical
intervals intersecting 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.
Sourcepub fn union_with_interval(&self, query: I) -> Self
pub fn union_with_interval(&self, query: I) -> Self
Returns the union of this set with query.
Intervals intersecting or adjacent to query are merged with it.
If query is disjoint from all existing intervals, it is inserted
at its canonical position.
Example:
set: [10, 20), [30, 40)
query: [20, 30)
out: [10, 40)Complexity: O(log n + n) because the returned immutable interval
slice must be allocated and populated.
Sourcepub fn difference_with_interval(&self, query: I) -> Self
pub fn difference_with_interval(&self, query: I) -> Self
Returns the difference of this set and query.
The operation removes every point covered by query from this set.
Intervals outside query are retained unchanged; intersecting boundary
intervals may be clipped into left and right residual segments.
Example:
set: [10, 20), [30, 40), [50, 60)
query: [15, 55)
out: [10, 15), [55, 60)Complexity: O(log n) if query is disjoint from the set; otherwise
O(n) because the returned immutable interval slice must be copied.
Sourcepub fn symmetric_difference_with_interval(&self, query: I) -> Self
pub fn symmetric_difference_with_interval(&self, query: I) -> Self
Returns the symmetric difference self △ query.
The returned set contains points covered by exactly one of self and
query.
Equivalently:
self △ query = (self ∪ query) \ (self ∩ query)Example:
self: [10, 20), [30, 40)
query: [15, 35)
out: [10, 15), [20, 30), [35, 40)Complexity: O(log n + k + n), where k is the number of canonical
intervals in the union component affected by query.
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn intersection_with_set(&self, other: &Self) -> Self
pub fn intersection_with_set(&self, other: &Self) -> Self
Returns the intersection of this set and other.
Both sets are canonical, so their sorted interval slices can be intersected with a two-pointer scan.
Example:
self: [0, 10), [20, 30), [40, 50)
other: [5, 25), [45, 60)
out: [5, 10), [20, 25), [45, 50)Complexity: O(n + m), where n and m are the canonical
interval counts of the two input sets.
pub fn union_with_set(&self, other: &Self) -> Self
Sourcepub fn difference_with_set(&self, other: &Self) -> Self
pub fn difference_with_set(&self, other: &Self) -> Self
Returns the difference of this set and other.
The returned set contains every point covered by self but not by
other.
Both source sets are canonical, so intervals from other are scanned
monotonically while residual segments from self are emitted.
Example:
self: [0, 10), [20, 30), [40, 50)
other: [5, 25), [45, 60)
out: [0, 5), [25, 30), [40, 45)Complexity: O(n + m), where n and m are the canonical
interval counts of the two input sets.
Sourcepub fn symmetric_difference_with_set(&self, other: &Self) -> Self
pub fn symmetric_difference_with_set(&self, other: &Self) -> Self
Returns the symmetric difference of this set and other.
The returned set contains every point covered by exactly one of the two input sets.
Both source sets are canonical. This method performs a two-way sweep over their virtual boundary events while tracking whether each side currently covers the sweep position.
Unlike an event-materializing implementation, the boundary event stream is represented by interval indices plus per-side coverage states:
- if a side is currently outside its current interval, the next event is that interval’s start;
- if a side is currently inside its current interval, the next event is that interval’s exclusive end.
Example:
self: [0, 10), [20, 30)
other: [5, 15), [25, 35)
out: [0, 5), [10, 15), [20, 25), [30, 35)Complexity: O(n + m), where n and m are the canonical interval
counts of the two input sets.
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub unsafe fn new_unchecked(intervals: Vec<I>) -> Self
pub unsafe fn new_unchecked(intervals: Vec<I>) -> Self
Builds a set from an already canonical interval vector.
§Safety
The caller must guarantee that intervals is canonical:
- intervals are sorted by ascending
start; - intervals are non-overlapping;
- contiguous intervals have already been merged;
- therefore, for every adjacent pair
a, b,a.end_excl() < b.start()holds.
Violating this invariant can make binary-search based queries return incorrect results.
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn covered_len_of(&self, query: I) -> I::MeasureType
pub fn covered_len_of(&self, query: I) -> I::MeasureType
Returns the covered length inside query.
Since IntCOSet<I> is canonical, all intersection segments are
disjoint, so summing their lengths is valid.
The result is always <= query.len().
Sourcepub fn uncovered_len_of(&self, query: I) -> I::MeasureType
pub fn uncovered_len_of(&self, query: I) -> I::MeasureType
Returns the uncovered length inside query.
Sourcepub fn coverage_ratio_f32_of(&self, query: I) -> f32
pub fn coverage_ratio_f32_of(&self, query: I) -> f32
Returns covered_len(query) / query.len() as f32.
query.len() is non-zero because I cannot represent an empty interval.
Sourcepub fn coverage_ratio_f64_of(&self, query: I) -> f64
pub fn coverage_ratio_f64_of(&self, query: I) -> f64
Returns covered_len(query) / query.len() as f64.
query.len() is non-zero because I cannot represent an empty interval.
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn contains_point(&self, x: I::CoordType) -> bool
pub fn contains_point(&self, x: I::CoordType) -> bool
Returns whether x is covered by any interval in the set.
Complexity: O(log n).
Sourcepub fn contains_interval(&self, query: I) -> bool
pub fn contains_interval(&self, query: I) -> 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: I) -> bool
pub fn intersects_interval(&self, query: I) -> bool
Returns whether query intersects any interval in the set.
Complexity: O(log n).
Source§impl<I: IntCO> IntCOSet<I>
impl<I: IntCO> IntCOSet<I>
Sourcepub fn intervals_intersecting(&self, query: I) -> impl Iterator<Item = I> + '_
pub fn intervals_intersecting(&self, query: I) -> impl Iterator<Item = I> + '_
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.
Trait Implementations§
Source§impl<I: IntCO> FromIterator<I> for IntCOSet<I>
impl<I: IntCO> FromIterator<I> for IntCOSet<I>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = I>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = I>,
Source§impl<I> FromParallelIterator<I> for IntCOSet<I>
impl<I> FromParallelIterator<I> for IntCOSet<I>
Source§fn from_par_iter<T>(iter: T) -> Selfwhere
T: IntoParallelIterator<Item = I>,
fn from_par_iter<T>(iter: T) -> Selfwhere
T: IntoParallelIterator<Item = I>,
par_iter. Read moreSource§impl<I: PartialEq + IntCO> PartialEq for IntCOSet<I>
impl<I: PartialEq + IntCO> PartialEq for IntCOSet<I>
impl<I: Eq + IntCO> Eq for IntCOSet<I>
impl<I: IntCO> StructuralPartialEq for IntCOSet<I>
Auto Trait Implementations§
impl<I> Freeze for IntCOSet<I>
impl<I> RefUnwindSafe for IntCOSet<I>where
I: RefUnwindSafe,
impl<I> Send for IntCOSet<I>
impl<I> Sync for IntCOSet<I>
impl<I> Unpin for IntCOSet<I>
impl<I> UnsafeUnpin for IntCOSet<I>
impl<I> UnwindSafe for IntCOSet<I>where
I: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more