Struct nested_intervals::IntervalSetGeneric
source · pub struct IntervalSetGeneric<T: Rangable + Debug> { /* private fields */ }
Expand description
IntervalSetGeneric
A collection of Range
If no ids are supplied, default ones will be provided. Merging functions return sorted ids Little assumption is placed on the intervals, they may overlap and nest. They must be start <= end though.
Our ranges are like Rust ranges, left closed, right open.
Internal storage is sorted by (start, -end), which is enforced at construction time.
Implementations§
source§impl<T: Rangable + Debug> IntervalSetGeneric<T>
impl<T: Rangable + Debug> IntervalSetGeneric<T>
sourcepub fn new(
intervals: &[Range<T>]
) -> Result<IntervalSetGeneric<T>, NestedIntervalError>
pub fn new( intervals: &[Range<T>] ) -> Result<IntervalSetGeneric<T>, NestedIntervalError>
Create an IntervalSet without supplying ids
ids will be 0..n in the order of the sorted intervals
sourcepub fn new_with_ids(
intervals: &[Range<T>],
ids: &[u32]
) -> Result<IntervalSetGeneric<T>, NestedIntervalError>
pub fn new_with_ids( intervals: &[Range<T>], ids: &[u32] ) -> Result<IntervalSetGeneric<T>, NestedIntervalError>
Create an IntervalSet
Ids may be non-unique This consumes both the intervals and ids which should safe an allocation in the most common use case
pub fn new_with_ids_multiple( intervals: &[Range<T>], ids: Vec<Vec<u32>> ) -> Result<IntervalSetGeneric<T>, NestedIntervalError>
sourcepub fn has_overlap(&self, query: &Range<T>) -> Result<bool, NestedIntervalError>
pub fn has_overlap(&self, query: &Range<T>) -> Result<bool, NestedIntervalError>
Is there any interval overlapping with the query?
sourcepub fn iter(&self) -> Zip<Iter<'_, Range<T>>, Iter<'_, Vec<u32>>>
pub fn iter(&self) -> Zip<Iter<'_, Range<T>>, Iter<'_, Vec<u32>>>
create an iterator over (Range<T>, &vec![id])
tuples.
sourcepub fn query_overlapping(&self, query: &Range<T>) -> IntervalSetGeneric<T>
pub fn query_overlapping(&self, query: &Range<T>) -> IntervalSetGeneric<T>
retrieve a new IntervalSet with all intervals overlapping the query
sourcepub fn any_overlapping(&self) -> bool
pub fn any_overlapping(&self) -> bool
does this IntervalSet contain overlapping intervals?
sourcepub fn overlap_status(&self) -> Vec<bool>
pub fn overlap_status(&self) -> Vec<bool>
which intervals are overlapping?
Result is a Vec
sourcepub fn any_nested(&self) -> bool
pub fn any_nested(&self) -> bool
does this IntervalSet contain nested intervals?
sourcepub fn remove_duplicates(&self) -> IntervalSetGeneric<T>
pub fn remove_duplicates(&self) -> IntervalSetGeneric<T>
remove intervals that have the same coordinates
Ids are not merged, the first set is being kept
sourcepub fn remove_empty(&self) -> IntervalSetGeneric<T>
pub fn remove_empty(&self) -> IntervalSetGeneric<T>
remove empty intervals, ie. those with start == end
sourcepub fn merge_hull(&self) -> IntervalSetGeneric<T>
pub fn merge_hull(&self) -> IntervalSetGeneric<T>
Merge overlapping & nested intervals to their outer bounds
Examples:
- 0..15, 10..20 -> 0..20
- 0..20, 3..5 -> 0..20
sourcepub fn merge_connected(&self) -> IntervalSetGeneric<T>
pub fn merge_connected(&self) -> IntervalSetGeneric<T>
Merge intervals that are butted up against each other
This first induces a merge_hull()!
Examples:
- 0..15, 15..20 -> 0..20
- 0..15, 16..20, 20..30 > 0..15, 16..30
sourcepub fn merge_drop(&self) -> IntervalSetGeneric<T>
pub fn merge_drop(&self) -> IntervalSetGeneric<T>
Remove all intervals that are overlapping or nested by simply dropping them.
Examples:
- 0..20, 10..15, 20..35, 30..40, 40..50 -> 40..50
Ids of the remaining intervals are unchanged
sourcepub fn merge_split(&self) -> IntervalSetGeneric<T>
pub fn merge_split(&self) -> IntervalSetGeneric<T>
Create fully disjoint intervals by splitting the existing ones based on their overlap.
Example:
- 0..20, 10..30 -> 0..10, 10..20, 20..30
Ids are merged, ie. in the above example,
if the input ids are [[0], [1]]
, the output ids are
[[0], [0,1], [1]]
merge_split on an already disjoint set is a no-op
sourcepub fn find_closest_start_left(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
pub fn find_closest_start_left(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
find the interval with the closest start to the left of pos None if there are no intervals to the left of pos
sourcepub fn find_closest_start_right(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
pub fn find_closest_start_right(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
find the interval with the closest start to the right of pos None if there are no intervals to the right of pos
sourcepub fn find_closest_start(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
pub fn find_closest_start(&self, pos: T) -> Option<(Range<T>, Vec<u32>)>
find the interval with the closest start to pos
None if the IntervalSet is empty On a tie, the left interval wins.
sourcepub fn covered_units(&self) -> T
pub fn covered_units(&self) -> T
how many units in interval space does this IntervalSet cover
sourcepub fn mean_interval_size(&self) -> f64
pub fn mean_interval_size(&self) -> f64
What is the mean size of the intervals
sourcepub fn invert(&self, lower_bound: T, upper_bound: T) -> IntervalSetGeneric<T>
pub fn invert(&self, lower_bound: T, upper_bound: T) -> IntervalSetGeneric<T>
Invert the intervals in this set
Actual applied lower_bound is min(lower_bound, first_interval_start) Actual applied upper_bound is max(upper_bound, last_interval_end)
Examples
- invert([15..20], 0, 30) -> [0..15, 20..30]
- invert([15..20], 20, 30) -> [0..15, 20..30]
Ids are lost
sourcepub fn filter_to_overlapping(
&self,
other: &IntervalSetGeneric<T>
) -> IntervalSetGeneric<T>
pub fn filter_to_overlapping( &self, other: &IntervalSetGeneric<T> ) -> IntervalSetGeneric<T>
Filter to those intervals that have an overlap in other.
sourcepub fn filter_to_overlapping_and_split(
&self,
other: &IntervalSetGeneric<T>
) -> IntervalSetGeneric<T>
pub fn filter_to_overlapping_and_split( &self, other: &IntervalSetGeneric<T> ) -> IntervalSetGeneric<T>
Filter to those intervals having an overlap in other, and split/truncate them so the resulting intervals are fully contained within the intervals covered by other. ids are being kept.
so 10..20 vs 5..11, 15..17, 18..30 -> 10..11, 15..17, 18..20
sourcepub fn filter_to_non_overlapping(
&self,
other: &IntervalSetGeneric<T>
) -> IntervalSetGeneric<T>
pub fn filter_to_non_overlapping( &self, other: &IntervalSetGeneric<T> ) -> IntervalSetGeneric<T>
Filter to those intervals that have no overlap in other.
sourcepub fn filter_to_overlapping_k_others(
&self,
others: &[&IntervalSetGeneric<T>],
min_k: u32
) -> IntervalSetGeneric<T>
pub fn filter_to_overlapping_k_others( &self, others: &[&IntervalSetGeneric<T>], min_k: u32 ) -> IntervalSetGeneric<T>
Filter to those intervals that have an overlap in at least k others.
sourcepub fn filter_to_non_overlapping_k_others(
&self,
others: &[&IntervalSetGeneric<T>],
max_k: u32
) -> IntervalSetGeneric<T>
pub fn filter_to_non_overlapping_k_others( &self, others: &[&IntervalSetGeneric<T>], max_k: u32 ) -> IntervalSetGeneric<T>
Filter to those intervals that have an overlap in no more than k others
sourcepub fn union(&self, others: &[&IntervalSetGeneric<T>]) -> IntervalSetGeneric<T>
pub fn union(&self, others: &[&IntervalSetGeneric<T>]) -> IntervalSetGeneric<T>
Build the union of two IntervalSets
No merging is performed
Trait Implementations§
source§impl<T: Rangable + Debug> Clone for IntervalSetGeneric<T>
impl<T: Rangable + Debug> Clone for IntervalSetGeneric<T>
source§fn clone(&self) -> IntervalSetGeneric<T>
fn clone(&self) -> IntervalSetGeneric<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Rangable + Debug> PartialEq for IntervalSetGeneric<T>
impl<T: Rangable + Debug> PartialEq for IntervalSetGeneric<T>
source§fn eq(&self, other: &IntervalSetGeneric<T>) -> bool
fn eq(&self, other: &IntervalSetGeneric<T>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<T: Rangable + Debug> Eq for IntervalSetGeneric<T>
Auto Trait Implementations§
impl<T> !Freeze for IntervalSetGeneric<T>
impl<T> !RefUnwindSafe for IntervalSetGeneric<T>
impl<T> Send for IntervalSetGeneric<T>where
T: Send,
impl<T> !Sync for IntervalSetGeneric<T>
impl<T> Unpin for IntervalSetGeneric<T>where
T: Unpin,
impl<T> UnwindSafe for IntervalSetGeneric<T>where
T: UnwindSafe,
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> 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