pub struct IntervalTree<T, D>where
T: IntervalType,{ /* private fields */ }
Expand description
An Interval Tree.
Implementations§
Source§impl<T, D> IntervalTree<T, D>where
T: IntervalType,
impl<T, D> IntervalTree<T, D>where
T: IntervalType,
Sourcepub fn new_from_entry<I>(entry: I) -> Selfwhere
I: Into<IntervalTreeEntry<T, D>>,
pub fn new_from_entry<I>(entry: I) -> Selfwhere
I: Into<IntervalTreeEntry<T, D>>,
Sourcepub fn insert<I>(&mut self, entry: I) -> &Selfwhere
I: Into<IntervalTreeEntry<T, D>>,
pub fn insert<I>(&mut self, entry: I) -> &Selfwhere
I: Into<IntervalTreeEntry<T, D>>,
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the IntervalTree
.
§Example
use space_partitioning::IntervalTree;
let tree = IntervalTree::new_from_entry((15..=20, "data"));
assert_eq!(tree.len(), 1);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the tree is empty, i.e., whether it has no elements.
§Example
use space_partitioning::IntervalTree;
let tree = IntervalTree::<i32, ()>::default();
assert!(tree.is_empty());
Sourcepub fn overlap_search<I>(&self, interval: I) -> Option<&IntervalTreeEntry<T, D>>
pub fn overlap_search<I>(&self, interval: I) -> Option<&IntervalTreeEntry<T, D>>
Queries the tree for overlaps with the specified interval
.
/// # Parameters
interval
- The interval to query for.
§Example
use space_partitioning::IntervalTree;
use space_partitioning::interval_tree::Interval;
let mut tree = IntervalTree::new_from_entry((15..=20, "A"));
tree.insert((100..=101, "B"));
let matched_a = tree.overlap_search(&(18..=25).into()).unwrap();
assert_eq!(matched_a.interval.start, 15);
assert_eq!(matched_a.interval.end, 20);
assert_eq!(matched_a.data, "A");
let matched_b = tree.overlap_search(&(100..=100).into()).unwrap();
assert_eq!(matched_b.interval.start, 100);
assert_eq!(matched_b.interval.end, 101);
assert_eq!(matched_b.data, "B");
let no_match = tree.overlap_search(0..=5);
assert!(no_match.is_none());
Sourcepub fn iter_inorder(&self) -> InorderIterator<'_, T, D> ⓘ
pub fn iter_inorder(&self) -> InorderIterator<'_, T, D> ⓘ
Returns an InorderIterator<T, D>
that iterates the tree elements in order
of their interval starts.
§Example
use space_partitioning::IntervalTree;
use std::iter::FromIterator;
let tree = IntervalTree::from_iter([(18..=25, "abc"), (0..=20, "xyz")]);
let mut iter = tree.iter_inorder();
let first = iter.next().unwrap();
assert_eq!(first.interval.start, 0);
assert_eq!(first.interval.end, 20);
assert_eq!(first.data, "xyz");
let second = iter.next().unwrap();
assert_eq!(second.interval.start, 18);
assert_eq!(second.interval.end, 25);
assert_eq!(second.data, "abc");
assert!(iter.next().is_none());
Trait Implementations§
Source§impl<T, D> Debug for IntervalTree<T, D>where
T: Debug + IntervalType,
impl<T, D> Debug for IntervalTree<T, D>where
T: Debug + IntervalType,
Source§impl<T, D> Default for IntervalTree<T, D>where
T: IntervalType,
impl<T, D> Default for IntervalTree<T, D>where
T: IntervalType,
Source§impl<T, D> From<(Interval<T>, D)> for IntervalTree<T, D>where
T: IntervalType,
impl<T, D> From<(Interval<T>, D)> for IntervalTree<T, D>where
T: IntervalType,
Source§impl<T> From<Interval<T>> for IntervalTree<T, ()>where
T: IntervalType,
impl<T> From<Interval<T>> for IntervalTree<T, ()>where
T: IntervalType,
Source§impl<I, T, D> FromIterator<I> for IntervalTree<T, D>
impl<I, T, D> FromIterator<I> for IntervalTree<T, D>
Source§fn from_iter<Iter>(iter: Iter) -> Selfwhere
Iter: IntoIterator<Item = I>,
fn from_iter<Iter>(iter: Iter) -> Selfwhere
Iter: IntoIterator<Item = I>,
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<T, D> Freeze for IntervalTree<T, D>
impl<T, D> RefUnwindSafe for IntervalTree<T, D>where
T: RefUnwindSafe,
D: RefUnwindSafe,
impl<T, D> Send for IntervalTree<T, D>
impl<T, D> Sync for IntervalTree<T, D>
impl<T, D> Unpin for IntervalTree<T, D>
impl<T, D> UnwindSafe for IntervalTree<T, D>where
T: UnwindSafe,
D: 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