Skip to main content

IntervalTree

Struct IntervalTree 

Source
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>

Source

pub fn from_unsorted(intervals: Vec<Interval<T>>) -> Self

Build an interval tree from unsorted intervals. O(n log n).

Source

pub fn from_sorted(intervals: Vec<Interval<T>>) -> Self

Build an interval tree from intervals sorted by start coordinate. O(n).

Source

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.

Source

pub fn count_overlaps(&self, start: u64, end: u64) -> usize

Count intervals overlapping the range [start, end) without allocating.

Source

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.

Source

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.

Source

pub fn following(&self, point: u64) -> Option<&Interval<T>>

Find the nearest interval that starts at or after point.

Returns the interval with the smallest start that is >= point.

Source

pub fn len(&self) -> usize

Number of intervals in the tree.

Source

pub fn is_empty(&self) -> bool

Whether the tree contains no intervals.

Source

pub fn iter(&self) -> impl Iterator<Item = &Interval<T>>

Iterate over all intervals in the tree (in-order traversal).

Trait Implementations§

Source§

impl<T: Clone> Clone for IntervalTree<T>

Source§

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

Returns a duplicate 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> Debug for IntervalTree<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for IntervalTree<T>

§

impl<T> RefUnwindSafe for IntervalTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for IntervalTree<T>
where T: Send,

§

impl<T> Sync for IntervalTree<T>
where T: Sync,

§

impl<T> Unpin for IntervalTree<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for IntervalTree<T>

§

impl<T> UnwindSafe for IntervalTree<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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.