Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion graphtage/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self,
self._constant_cost = constant_cost
self._cost_upper_bound = cost_upper_bound
self._valid: bool = True
self._cached_bounds: Optional[Range] = None
self.initial_bounds = self.bounds()
"""The initial bounds of this edit.

Expand Down Expand Up @@ -128,6 +129,8 @@ def bounds(self) -> Range:
Range: A range bounding the cost of this edit.

"""
if self._cached_bounds is not None:
return self._cached_bounds
lb = self._constant_cost
if self._cost_upper_bound is None:
if self.to_node is None:
Expand All @@ -136,7 +139,13 @@ def bounds(self) -> Range:
ub = self.from_node.total_size + self.to_node.total_size + 1
else:
ub = self._cost_upper_bound
return Range(lb, ub)
result = Range(lb, ub)
self._cached_bounds = result
return result

def invalidate_bounds_cache(self):
"""Invalidate the cached bounds. Call this when bounds may have changed."""
self._cached_bounds = None


class ConstantCostEdit(AbstractEdit, ABC):
Expand Down
Loading