Struct space_partitioning::interval_tree::IntervalTree[][src]

pub struct IntervalTree<T, D> where
    T: IntervalType
{ /* fields omitted */ }
Expand description

An Interval Tree.

Implementations

pub fn new_from_entry<I>(entry: I) -> Self where
    I: Into<IntervalTreeEntry<T, D>>, 

Creates a new IntervalTree from a root entry.

Parameters

  • entry - The first entry.

Example

use space_partitioning::IntervalTree;
let tree = IntervalTree::new_from_entry((15..=20, "data"));
assert_eq!(tree.len(), 1);

Inserts a new entry to the IntervalTree.

Parameters

  • entry - The entry to insert.

Example

use space_partitioning::IntervalTree;
let mut tree = IntervalTree::default();
tree.insert((15..=20, "data"));
assert_eq!(tree.len(), 1);

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);

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());

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());

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

Formats the value using the given formatter. Read more

Returns an empty IntervalTree<T, D>.

Example

use space_partitioning::IntervalTree;
let tree = IntervalTree::<i32, ()>::default();
assert_eq!(tree.len(), 0);

Performs the conversion.

Performs the conversion.

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.