pub struct IntervalTree<T: Clone + Eq + Hash> { /* private fields */ }Expand description
Custom interval tree optimized for spreadsheet cell indexing.
§Design decisions:
- Point intervals are the common case - Most cells are single points [r,r] or [c,c]
- Sparse data - Even million-row sheets typically have <10K cells
- Batch updates - During shifts, we update many intervals at once
- Small value sets - Each interval maps to a small set of VertexIds
§Implementation:
Uses an augmented BST where each node stores:
- Interval [low, high]
- Max endpoint in subtree (for efficient pruning)
- Value set (HashSet
)
This is simpler than generic interval trees because we optimize for our specific use case.
Implementations§
Source§impl<T: Clone + Eq + Hash> IntervalTree<T>
impl<T: Clone + Eq + Hash> IntervalTree<T>
Sourcepub fn insert(&mut self, low: u32, high: u32, value: T)
pub fn insert(&mut self, low: u32, high: u32, value: T)
Insert a value for the given interval [low, high]
Sourcepub fn remove(&mut self, low: u32, high: u32, value: &T) -> bool
pub fn remove(&mut self, low: u32, high: u32, value: &T) -> bool
Remove a value from the interval [low, high]
Sourcepub fn query(
&self,
query_low: u32,
query_high: u32,
) -> Vec<(u32, u32, HashSet<T>)>
pub fn query( &self, query_low: u32, query_high: u32, ) -> Vec<(u32, u32, HashSet<T>)>
Query all intervals that overlap with [query_low, query_high]
Sourcepub fn get_mut(&mut self, low: u32, high: u32) -> Option<&mut HashSet<T>>
pub fn get_mut(&mut self, low: u32, high: u32) -> Option<&mut HashSet<T>>
Get mutable reference to values for an exact interval match
Sourcepub fn entry(&mut self, low: u32, high: u32) -> Entry<'_, T>
pub fn entry(&mut self, low: u32, high: u32) -> Entry<'_, T>
Entry API for convenient insert-or-update operations
Sourcepub fn bulk_build_points(&mut self, items: Vec<(u32, HashSet<T>)>)
pub fn bulk_build_points(&mut self, items: Vec<(u32, HashSet<T>)>)
Bulk build optimization for a collection of point intervals [x,x]. Expects (low == high) for all items. Existing content is discarded if tree is empty; if not empty, falls back to incremental inserts.
Trait Implementations§
Source§impl<T: Clone + Clone + Eq + Hash> Clone for IntervalTree<T>
impl<T: Clone + Clone + Eq + Hash> Clone for IntervalTree<T>
Source§fn clone(&self) -> IntervalTree<T>
fn clone(&self) -> IntervalTree<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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>
impl<T> UnwindSafe for IntervalTree<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
Mutably borrows from an owned value. Read more
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>
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 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>
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