Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complexity of IntervalTree.{begin,end} is O(1), not O(n). #40

Merged
merged 1 commit into from
Dec 10, 2017

Conversation

progval
Copy link
Contributor

@progval progval commented Mar 15, 2016

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:

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
@chaimleib chaimleib changed the base branch from master to dev December 10, 2017 19:23
@chaimleib
Copy link
Owner

Thanks!

@chaimleib chaimleib merged commit 02f40c6 into chaimleib:dev Dec 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants