summaryrefslogtreecommitdiff
path: root/math_utils.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-07-04 00:33:26 -0700
committerScott Gasch <[email protected]>2022-07-04 00:33:26 -0700
commit72d255e75695973843f05f5bd60fb415ff782ffe (patch)
treee9f6219796ee30005d1f23ac76e0ead8c826a105 /math_utils.py
parente4f0a5a96d6435166699cc1131f655c8904c1ddd (diff)
Add inital cut of iter_utils with a coupel of iters I needed. Tweak
math_utils population.
Diffstat (limited to 'math_utils.py')
-rw-r--r--math_utils.py6
1 files changed, 6 insertions, 0 deletions
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: