#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
"""This is an augmented interval tree for storing ranges and identifying overlaps as
described by: https://en.wikipedia.org/wiki/Interval_tree.
"""
from __future__ import annotations
from functools import total_ordering
-from typing import Any, Generator, Optional, Union
+from typing import Any, Generator, Optional
from overrides import overrides
from pyutils.collectionz import bst
-
-Numeric = Union[int, float]
+from pyutils.types.simple import Numeric
@total_ordering
self.highest_in_subtree: Numeric = high
def __lt__(self, other: NumericRange) -> bool:
- return self.low < other.low
+ """
+ Returns:
+ True is this range is less than (lower low) other, else False.
+ """
+ if self.low != other.low:
+ return self.low < other.low
+ else:
+ return self.high < other.high
@overrides
def __eq__(self, other: object) -> bool:
+ """
+ Returns:
+ True if this is the same range as other, else False.
+ """
if not isinstance(other, NumericRange):
return False
return self.low == other.low and self.high == other.high
def overlaps_with(self, other: NumericRange) -> bool:
+ """
+ Returns:
+ True if this NumericRange overlaps with other, else False.
+ """
return self.low <= other.high and self.high >= other.low
def __repr__(self) -> str: