Enum NestedIntervalTree

Source
pub enum NestedIntervalTree<T> {
    Node(IntervalMap<usize, Box<NestedIntervalTree<T>>>),
    Leaf(T),
}
Expand description

An enumeration representing a recursive interval tree that can contain either an inner node with associated intervals or a terminal leaf with a stored value.

The inner node variant encapsulates an interval map associating ranges (identified by usize keys) to boxed nested trees, enabling hierarchical and ordered organization of intervals. In contrast, the leaf variant holds a direct value, serving as the base case in this nested tree structure.

Variants§

Implementations§

Source§

impl<T: Clone> NestedIntervalTree<T>

Source

pub fn build( ranges: impl Iterator<Item = impl Iterator<Item = Range<usize>>> + Clone, value: T, ) -> Self

Builds a nested interval tree by recursively processing an iterator of range iterators and embedding a terminal value when no more ranges remain.

Recursively processes the outer iterator such that if a current iterator exists, it iterates over its ranges and creates subtrees for each by cloning the remaining iterators and value; otherwise, it produces a leaf containing the provided value. This design constructs a hierarchical structure where each node associates intervals with nested subtrees, culminating in leaves holding the synthesized value.

Source

pub fn insert_using_iter<'a: 'b, 'b>( &'a mut self, ranges: impl Iterator<Item = impl Iterator<Item = Range<usize>> + 'b> + Clone + 'b, update: &impl Fn(&mut T), default: T, )

Inserts elements into a nested interval structure by recursively traversing an iterator over iterators of range indices to either update existing leaf values or create new branches with default values.

The function operates by taking an iterator of iterators of ranges, a function to update leaf values, and a default value. For an internal node, it iterates over each range from the provided iterator: if a corresponding child exists, it recurses into that child with cloned iterators; if not, it creates a new branch using the default value. When a leaf node is reached and there are no more ranges, it applies the update function to modify the leaf’s contained value. The function will panic if the provided range structure does not match the depth of the tree.

Source

pub fn insert_multiple<'a: 'b, 'b>( &'a mut self, ranges: &Vec<Vec<Range<usize>>>, value: T, )

Inserts a value at a nested tree leaf corresponding to a multi-dimensional sequence of interval ranges.

Uses a vector of interval range vectors to represent the nesting levels, delegating recursive insertion to a helper that traverses and builds intermediate nodes as needed, while using a no-op update function for branch nodes.

Source

pub fn insert<'a: 'b, 'b>(&'a mut self, ranges: &[Range<usize>], value: T)

Inserts a value into the nested interval tree using a provided slice of ranges. This function transforms the slice of ranges into an iterator of one-item iterators and then delegates to the internal insertion procedure that supports multi-level range specifications.

Source§

impl<T> NestedIntervalTree<T>

Source

pub fn new() -> Self

Creates an empty nested interval tree by initializing it as a node containing an empty interval map. This function serves as a constructor for the tree structure, providing a starting point for inserting ranges and associated values in later operations.

Source

pub fn get(&self, ranges: &[Range<usize>]) -> Option<&T>

Retrieves a stored value by following a sequence of interval ranges across a nested data structure.

This function accepts a slice of range indices that represent a traversal path through nested intervals. It navigates the structure by, for non-empty range sequences, using the first range to determine which subtree to search and recursing with the remaining ranges, while returning the leaf’s value if there are no ranges left. If the provided path does not match the structure, it results in a None.

Source

pub fn superrange_using_iter<'a: 'b, 'b>( &'a self, ranges: impl Iterator<Item = impl Iterator<Item = Range<usize>> + 'b> + Clone + 'b, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Returns an iterator over all values in the tree that are reachable via a chain of intervals where each enclosing interval is a superrange of the corresponding query range.

This method recursively traverses a nested interval structure using an iterator of iterators of ranges; in internal nodes it filters subintervals that fully contain the query interval and descends recursively, while at a leaf node with no remaining query ranges it yields the stored value. It panics if the depth of provided range sequences does not match the tree structure.

Source

pub fn subrange_using_iter<'a: 'b, 'b>( &'a self, ranges: impl Iterator<Item = impl Iterator<Item = Range<usize>> + 'b> + Clone + 'b, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Returns an iterator over subrange-matching values from a nested interval tree structure based on a sequence of range iterators.

Processes a cloned iterator yielding iterators over range indices, where at each node it filters for entries whose ranges are completely contained within the provided range, and recursively applies the same filtering on the resulting subtrees. In the leaf case when no further range iterator is provided, it yields the leaf value, while differing iterator depths result in a runtime panic.

Source

pub fn superrange_multiple<'a: 'b, 'b>( &'a self, ranges: &'b Vec<Vec<Range<usize>>>, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Returns an iterator over all values whose associated intervals contain the specified super ranges.

Delegates to a lower-level iterator implementation by mapping the provided vector of range vectors into an appropriate iterator form for traversing the nested interval structure, ultimately yielding references to values that satisfy the super-range condition.

Source

pub fn subrange_multiple<'a: 'b, 'b>( &'a self, ranges: &'b Vec<Vec<Range<usize>>>, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Returns an iterator over elements from nested intervals that are enclosed by the specified multiple subrange lists provided as a vector of vectors.

Invokes an internal subrange retrieval function by mapping the provided vector of range lists into an iterator of cloned ranges, thereby allowing the caller to iterate over all matching elements in the tree that fall within the prescribed nested subranges.

Source

pub fn superrange<'a: 'b, 'b>( &'a self, ranges: Vec<Range<usize>>, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Return an iterator yielding references to values whose associated intervals form a superrange of the provided sequence of index ranges. This function converts a vector of ranges into the expected single-element iterators and delegates the lookup to the underlying superrange retrieval logic, thereby providing access to all elements that satisfy the defined superrange condition.

Source

pub fn subrange<'a: 'b, 'b>( &'a self, ranges: Vec<Range<usize>>, ) -> Box<dyn Iterator<Item = &'b T> + 'b>

Returns a boxed iterator over references to values matching the provided subrange specification.

Maps the given vector of ranges into the expected iterator form and delegates to an underlying iterator-based subrange retrieval method to extract matching elements from the nested structure.

Trait Implementations§

Source§

impl<T> Default for NestedIntervalTree<T>

Source§

fn default() -> Self

Returns a default instance by invoking the constructor for a new instance. This implementation enables the use of default() to create an object with initial empty configuration without the need for manual initialization.

Auto Trait Implementations§

§

impl<T> Freeze for NestedIntervalTree<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NestedIntervalTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for NestedIntervalTree<T>
where T: Send,

§

impl<T> Sync for NestedIntervalTree<T>
where T: Sync,

§

impl<T> Unpin for NestedIntervalTree<T>
where T: Unpin,

§

impl<T> UnwindSafe for NestedIntervalTree<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AllocForAny<T> for T

Source§

fn galloc(self) -> &'static T

Provides a method to allocate an instance of T on the heap with a static lifetime.

This implementation of galloc takes ownership of the T instance and uses the alloc function to place it in a location with a static lifetime, presumably managing it in a way that ensures its persistence for the duration of the program. This can be particularly useful for scenarios where a static lifetime is required, such as when interfacing with systems or patterns that necessitate global state or long-lived data.

Source§

fn galloc_mut(self) -> &'static T

Provides a method that moves the instance and returns a reference to it allocated with a static lifetime.

This method utilizes alloc_mut to perform the allocation, likely involving allocating the resource in a manner that ensures it lives for the entire duration of the application. These semantics allow the user to safely assume that the reference will not expire during the program’s execution, making it suitable for long-lived data structures or operations that require such guarantees.

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V