Skip to content

Commit

Permalink
Merge pull request #66 from chaimleib/dev
Browse files Browse the repository at this point in the history
faster interval overlaps #56
  • Loading branch information
chaimleib authored Dec 11, 2017
2 parents 2d1b463 + ce4b52a commit 1ff87c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Version 3.0.0
- Dropped support for Python 2.6, 3.2, and 3.3
- Add support for Python 3.5 and 3.6
- Faster `Interval` overlap checking (@tuxzz, #56)
- Updated README:
- new restructuring methods from 2.1.0
- example of `from_tuples()` added
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Version 3.0.0

- Dropped support for Python 2.6, 3.2, and 3.3
- Add support for Python 3.5 and 3.6
- Faster ``Interval`` overlap checking (@tuxzz, #56)
- Updated README:

- new restructuring methods from 2.1.0
Expand Down
12 changes: 6 additions & 6 deletions intervaltree/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def overlaps(self, begin, end=None):
:rtype: bool
"""
if end is not None:
return (
(begin <= self.begin < end) or
(begin < self.end <= end) or
(self.begin <= begin < self.end) or
(self.begin < end <= self.end)
)
# An overlap means that some C exists that is inside both ranges:
# begin <= C < end
# and
# self.begin <= C < self.end
# See https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-two-integer-ranges-for-overlap/3269471#3269471
return begin < self.end and end > self.begin
try:
return self.overlaps(begin.begin, begin.end)
except:
Expand Down

0 comments on commit 1ff87c1

Please sign in to comment.