Struct nested_intervals::IntervalSetGeneric

source ·
pub struct IntervalSetGeneric<T: Rangable + Debug> { /* private fields */ }
Expand description

IntervalSetGeneric

A collection of Range and associated ids (u32).

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>

source

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

source

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

source

pub fn new_with_ids_multiple( intervals: &[Range<T>], ids: Vec<Vec<u32>> ) -> Result<IntervalSetGeneric<T>, NestedIntervalError>

source

pub fn len(&self) -> usize

How many intervals are there?

source

pub fn is_empty(&self) -> bool

Is the number of intervals 0?

source

pub fn has_overlap(&self, query: &Range<T>) -> Result<bool, NestedIntervalError>

Is there any interval overlapping with the query?

source

pub fn iter(&self) -> Zip<Iter<'_, Range<T>>, Iter<'_, Vec<u32>>>

create an iterator over (Range<T>, &vec![id]) tuples.

source

pub fn query_overlapping(&self, query: &Range<T>) -> IntervalSetGeneric<T>

retrieve a new IntervalSet with all intervals overlapping the query

source

pub fn any_overlapping(&self) -> bool

does this IntervalSet contain overlapping intervals?

source

pub fn overlap_status(&self) -> Vec<bool>

which intervals are overlapping?

Result is a Vec

source

pub fn any_nested(&self) -> bool

does this IntervalSet contain nested intervals?

source

pub fn remove_duplicates(&self) -> IntervalSetGeneric<T>

remove intervals that have the same coordinates

Ids are not merged, the first set is being kept

source

pub fn remove_empty(&self) -> IntervalSetGeneric<T>

remove empty intervals, ie. those with start == end

source

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
source

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
source

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

source

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

source

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

source

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

source

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.

source

pub fn covered_units(&self) -> T

how many units in interval space does this IntervalSet cover

source

pub fn mean_interval_size(&self) -> f64

What is the mean size of the intervals

source

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

source

pub fn filter_to_overlapping( &self, other: &IntervalSetGeneric<T> ) -> IntervalSetGeneric<T>

Filter to those intervals that have an overlap in other.

source

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

source

pub fn filter_to_non_overlapping( &self, other: &IntervalSetGeneric<T> ) -> IntervalSetGeneric<T>

Filter to those intervals that have no overlap in other.

source

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.

source

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

source

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>

source§

fn clone(&self) -> IntervalSetGeneric<T>

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<T: Debug + Rangable + Debug> Debug for IntervalSetGeneric<T>

source§

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

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

impl<T: Rangable + Debug> PartialEq for IntervalSetGeneric<T>

source§

fn eq(&self, other: &IntervalSetGeneric<T>) -> 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<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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.