Skip to content

Commit

Permalink
make Cluster.stop in coalesce module a managed property (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoladze authored Oct 23, 2024
1 parent de2f0d5 commit afca74c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/uproot/source/coalesce.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RangeRequest:
@dataclass
class Cluster:
ranges: list[RangeRequest]
_stop: int | None = None

@property
def start(self):
Expand All @@ -57,7 +58,13 @@ def start(self):

@property
def stop(self):
return max(range.stop for range in self.ranges)
# Note: in order for this to work one has to use `append` for adding new ranges
return self._stop

def append(self, range):
if self._stop is None or range.stop > self._stop:
self._stop = range.stop
self.ranges.append(range)

def __len__(self):
return self.stop - self.start
Expand Down Expand Up @@ -88,7 +95,7 @@ def _merge_adjacent(ranges: list[RangeRequest], config: CoalesceConfig):
if cluster.ranges and current_range.start - cluster.stop > config.max_range_gap:
yield cluster
cluster = Cluster([])
cluster.ranges.append(current_range)
cluster.append(current_range)
if cluster.ranges:
yield cluster

Expand Down

0 comments on commit afca74c

Please sign in to comment.