From 72d255e75695973843f05f5bd60fb415ff782ffe Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Mon, 4 Jul 2022 00:33:26 -0700 Subject: Add inital cut of iter_utils with a coupel of iters I needed. Tweak math_utils population. --- math_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'math_utils.py') diff --git a/math_utils.py b/math_utils.py index 64cd9fb..ed9c2f4 100644 --- a/math_utils.py +++ b/math_utils.py @@ -41,6 +41,8 @@ class NumericPopulation(object): self.lowers, self.highers = [], [] self.aggregate = 0.0 self.sorted_copy: Optional[List[float]] = None + self.maximum = None + self.minimum = None def add_number(self, number: float): """Adds a number to the population. Runtime complexity of this @@ -52,6 +54,10 @@ class NumericPopulation(object): heappush(self.lowers, -number) # for lowers we need a max heap self.aggregate += number self._rebalance() + if not self.maximum or number > self.maximum: + self.maximum = number + if not self.minimum or number < self.minimum: + self.minimum = number def _rebalance(self): if len(self.lowers) - len(self.highers) > 1: -- cgit v1.3