pub struct IntervalSet<T, V> { /* private fields */ }Expand description
A mutable interval collection with stable identifiers.
Unlike IntervalTree, this collection supports dynamic insertion
and removal. Each inserted interval receives a stable IntervalId
that remains valid until the interval is removed.
Internally maintains a pending buffer that gets merged into an optimized tree structure on query.
§Example
use simd_intervaltree::IntervalSet;
let mut set = IntervalSet::new();
// Insert returns stable IDs
let id1 = set.insert(0..10, "first");
let id2 = set.insert(5..15, "second");
// Query overlapping intervals with IDs
for (id, interval, value) in set.query(3..12) {
println!("{id:?}: {interval:?} => {value}");
}
// Remove by ID
set.remove(id1);Implementations§
Source§impl<T, V> IntervalSet<T, V>
impl<T, V> IntervalSet<T, V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new interval set with the specified capacity.
Source§impl<T: Ord + Copy, V> IntervalSet<T, V>
impl<T: Ord + Copy, V> IntervalSet<T, V>
Sourcepub fn insert<R: Into<Interval<T>>>(&mut self, range: R, value: V) -> IntervalId
pub fn insert<R: Into<Interval<T>>>(&mut self, range: R, value: V) -> IntervalId
Inserts an interval with its associated value.
Returns a stable IntervalId that can be used for removal
or mapping to external resources.
Sourcepub fn remove(&mut self, id: IntervalId) -> bool
pub fn remove(&mut self, id: IntervalId) -> bool
Removes an interval by its ID.
Returns true if the interval was found and removed.
Sourcepub fn get(&self, id: IntervalId) -> Option<&V>
pub fn get(&self, id: IntervalId) -> Option<&V>
Returns the value associated with an interval ID, if it exists.
Sourcepub fn get_interval(&self, id: IntervalId) -> Option<Interval<T>>
pub fn get_interval(&self, id: IntervalId) -> Option<Interval<T>>
Returns the interval associated with an ID, if it exists.
Sourcepub fn query<R: Into<Interval<T>>>(
&mut self,
range: R,
) -> impl Iterator<Item = (IntervalId, Interval<T>, &V)>
pub fn query<R: Into<Interval<T>>>( &mut self, range: R, ) -> impl Iterator<Item = (IntervalId, Interval<T>, &V)>
Queries for all intervals overlapping the given range.
Returns an iterator yielding (IntervalId, Interval<T>, &V) tuples.
This may trigger an internal rebuild if the collection has been modified.
Trait Implementations§
Source§impl<T: Clone, V: Clone> Clone for IntervalSet<T, V>
impl<T: Clone, V: Clone> Clone for IntervalSet<T, V>
Source§fn clone(&self) -> IntervalSet<T, V>
fn clone(&self) -> IntervalSet<T, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more