Struct NonOverlappingIntervalTree

Source
pub struct NonOverlappingIntervalTree<K, V> { /* private fields */ }
Expand description

An implementation of a non-overlapping interval tree.

Keys are ranges, Range, and values are stored for a given range. Ranges inside the tree map not overlap, and the insert function enforces this. Internally managed by a BTreeMap.

Implementations§

Source§

impl<K, V> NonOverlappingIntervalTree<K, V>

Source

pub fn new() -> Self

Construct a new non-overlapping interval tree.

Source§

impl<K: Ord + Clone, V> NonOverlappingIntervalTree<K, V>

Source

pub fn insert(&mut self, int: Range<K>, val: V) -> Option<V>

Insert a value into the tree for a given range, not checking to see if any overlapping occurs. If there’s an element whose range starts with int’s start, that element is removed and returned.

§Note

This function can potentially corrupt the tree, since the normal operation functions rely on there being no overlaps. Care must be taken when using this function to ensure the no-overlap property manually.

Source

pub fn insert_replace(&mut self, int: Range<K>, val: V) -> Vec<(Range<K>, V)>

Insert a value into the tree for a given range, removing and returning all K,V pairs that are in the tree that overlap with the inserted range.

§Examples
use nonoverlapping_interval_tree::NonOverlappingIntervalTree;
let mut it = NonOverlappingIntervalTree::new();
it.insert_replace(1..3, "hello");
Source

pub fn get(&self, point: &K) -> Option<&V>

Get an immutable reference to the value of a single point in the interval tree, returning the value for a range that contains this point if one exists.

Source

pub fn get_mut(&mut self, point: &K) -> Option<&mut V>

Get a mutable reference to the value of a single point in the interval tree, returning the value for a range that contains this point if one exists.

Source

pub fn remove(&mut self, point: &K) -> Option<V>

Remove the value associated with the range that contains the point argument. If one is present, it is removed and returned, otherwise None is returned.

Source

pub fn range(&self, range: Range<K>) -> ValueRange<'_, K, IntervalValue<K, V>>

Returns a double-ended iterator over a sub-range of elements in the map. The resulting range may contain individual points that are not in the provided range if the stored ranges overlap with the terminating point. For example, if the tree contains [[1..3], [4..6]], and you call tree.range(1..5), you’ll get back [[1..3], [4..6]], since the 4..6 range contains 4 as requested by the call to range.

Source

pub fn range_mut( &mut self, range: Range<K>, ) -> ValueRangeMut<'_, K, IntervalValue<K, V>>

Returns a mutable double-ended iterator over a sub-range of elements in the map. The resulting range may contain individual points that are not in the provided range if the stored ranges overlap with the terminating point. For example, if the tree contains [[1..3], [4..6]], and you call tree.range(1..5), you’ll get back [[1..3], [4..6]], since the 4..6 range contains 4 as requested by the call to range.

Source

pub fn clear(&mut self)

Remove all elements in the tree.

Source

pub fn iter(&self) -> Iter<'_, K, IntervalValue<K, V>>

Return an iterator for the tree, sorted by key.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, IntervalValue<K, V>>

Return an iterator for the tree, sorted by key.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Trait Implementations§

Source§

impl<K: Clone, V: Clone> Clone for NonOverlappingIntervalTree<K, V>

Source§

fn clone(&self) -> NonOverlappingIntervalTree<K, V>

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<K: Debug, V: Debug> Debug for NonOverlappingIntervalTree<K, V>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for NonOverlappingIntervalTree<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for NonOverlappingIntervalTree<K, V>

§

impl<K, V> RefUnwindSafe for NonOverlappingIntervalTree<K, V>

§

impl<K, V> Send for NonOverlappingIntervalTree<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for NonOverlappingIntervalTree<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for NonOverlappingIntervalTree<K, V>

§

impl<K, V> UnwindSafe for NonOverlappingIntervalTree<K, V>

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