Mojo struct
IntervalTree
struct IntervalTree[T: IntervalElement, U: Copyable & Comparable & Writable]
An interval tree data structure for efficient range queries.
Parameters
- T (
IntervalElement): The type of the interval bounds, must support subtraction, integer conversion, string conversion, comparison and collection operations. - U (
Copyable&Comparable&Writable): The type of the associated data, must support string conversion and collection operations.
Implemented traits
AnyType,
Defaultable,
ImplicitlyDestructible,
Writable
Methods
__init__
__init__(out self)
Initializes an empty IntervalTree.
__del__
__del__(deinit self)
Destructor that frees the interval tree's memory.
insert
insert(mut self, interval: Tuple[T, T], data: U)
Insert a new interval into the tree using a tuple representation.
Args:
- interval (
Tuple): A tuple containing the start and end values of the interval. - data (
U): The data value to associate with this interval.
insert(mut self, interval: Interval[T], data: U)
Insert a new interval into the tree.
This method inserts a new interval and its associated data into the interval tree. It maintains the binary search tree property based on interval start times and updates the tree structure to preserve red-black tree properties.
Args:
- interval (
Interval): The interval to insert into the tree. - data (
U): The data value to associate with this interval.
write_to
write_to(self, mut writer: T)
Writes the interval tree to a writer.
Args:
- writer (
T): The writer to write the interval tree to.
write_repr_to
write_repr_to(self, mut writer: T)
Write the repr of this IntervalTree to a writer.
Args:
- writer (
T): The object to write to.
depth
depth(self) -> Int
Returns the depth of the interval tree.
Returns:
Int: The depth of the interval tree.
transplant
transplant(mut self, mut u: Optional[NonNullUnsafePointer[_IntervalNode[T, U], MutExternalOrigin]], mut v: Optional[NonNullUnsafePointer[_IntervalNode[T, U], MutExternalOrigin]])
Transplants the subtree rooted at node u with the subtree rooted at node v.
Args:
search
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!