pub struct IntervalTree<T> { /* private fields */ }Expand description
A static augmented interval tree using an implicit BST layout.
Built once from a set of intervals, then supports efficient overlap queries. The tree cannot be modified after construction.
Implementations§
Source§impl<T> IntervalTree<T>
impl<T> IntervalTree<T>
Sourcepub fn from_unsorted(intervals: Vec<Interval<T>>) -> Self
pub fn from_unsorted(intervals: Vec<Interval<T>>) -> Self
Build an interval tree from unsorted intervals. O(n log n).
Sourcepub fn from_sorted(intervals: Vec<Interval<T>>) -> Self
pub fn from_sorted(intervals: Vec<Interval<T>>) -> Self
Build an interval tree from intervals sorted by start coordinate. O(n).
Sourcepub fn query(&self, start: u64, end: u64) -> Vec<&Interval<T>>
pub fn query(&self, start: u64, end: u64) -> Vec<&Interval<T>>
Query all intervals overlapping the range [start, end).
Returns references to all intervals where interval.start < end && interval.end > start.
Sourcepub fn count_overlaps(&self, start: u64, end: u64) -> usize
pub fn count_overlaps(&self, start: u64, end: u64) -> usize
Count intervals overlapping the range [start, end) without allocating.
Sourcepub fn nearest(&self, point: u64) -> Option<&Interval<T>>
pub fn nearest(&self, point: u64) -> Option<&Interval<T>>
Find the nearest interval to a point.
Returns the interval whose midpoint is closest to point.
If multiple intervals are equidistant, returns one arbitrarily.
Sourcepub fn preceding(&self, point: u64) -> Option<&Interval<T>>
pub fn preceding(&self, point: u64) -> Option<&Interval<T>>
Find the nearest interval that ends at or before point.
Returns the interval with the largest end that is <= point.
Trait Implementations§
Source§impl<T: Clone> Clone for IntervalTree<T>
impl<T: Clone> Clone for IntervalTree<T>
Source§fn clone(&self) -> IntervalTree<T>
fn clone(&self) -> IntervalTree<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more