Skip to content

Commit e3f747d

Browse files
committed
Complexity of IntervalTree.{begin,end} is O(1), not O(n).
They call self.boundary_table.iloc[0] (resp. [-1]), and self.boundary_table is a SortedDict. SortedDict.iloc is an instance of _IlocWrapper, whose __getitem__ only does: return self._dict._list[index] _dict is the SortedDict instance, and _dict._list is an instance of SortedList. Finally, SortedList.__item__ has special cases to perform in O(1) when the index is 0 or -1. References: * https://github.com/grantjenks/sorted_containers/blob/ccec8d4/sortedcontainers/sorteddict.py#L34-L40 * https://github.com/grantjenks/sorted_containers/blob/b62fe6a/sortedcontainers/sortedlist.py#L599-L602
1 parent 30fdc1b commit e3f747d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

intervaltree/intervaltree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def begin(self):
818818
"""
819819
Returns the lower bound of the first interval in the tree.
820820
821-
Completes in O(n) time.
821+
Completes in O(1) time.
822822
"""
823823
if not self.boundary_table:
824824
return 0
@@ -828,7 +828,7 @@ def end(self):
828828
"""
829829
Returns the upper bound of the last interval in the tree.
830830
831-
Completes in O(n) time.
831+
Completes in O(1) time.
832832
"""
833833
if not self.boundary_table:
834834
return 0

0 commit comments

Comments
 (0)