Skip to content

Commit

Permalink
Rewrite #65
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDecan committed Sep 12, 2021
1 parent d7016b7 commit c48515d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

### Added
- Support [PEP 517](https://www.python.org/dev/peps/pep-0517).

### Changed
- Some internal changes to ease subclassing `Interval`(see [#58](https://github.com/AlexandreDecan/portion/issues/58)):
* Use `self.__class__` instead of `Interval` to create new instances;
* Deprecate and move `mergeable` function to `Interval._mergeable` class method;
* `Interval.from_atomic` is now a class method instead of a static method.

- Speed up lookups in `IntervalDict` ([#65](https://github.com/AlexandreDecan/portion/issues/58), Jeff Trull).


## 2.1.6 (2021-04-17)
Expand Down
10 changes: 6 additions & 4 deletions portion/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,13 @@ def as_dict(self):

def __getitem__(self, key):
if isinstance(key, Interval):
# No need to consider intervals with left boundary > key.upper
max_key = (key.upper, True)

upper = key.upper
items = []
for i in self._storage.irange_key(max_key=max_key):
for i, v in self._storage.items():
# Early out
if upper < i.lower:
break

intersection = key & i
if not intersection.empty:
items.append((intersection, self._storage[i]))
Expand Down

0 comments on commit c48515d

Please sign in to comment.