projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add inital cut of iter_utils with a coupel of iters I needed. Tweak
[python_utils.git]
/
math_utils.py
diff --git
a/math_utils.py
b/math_utils.py
index 64cd9fb65839503b72baf5d3f95adbeb5a441101..ed9c2f450f0fb0a9b121069a19d4a0b1fe7acfba 100644
(file)
--- 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.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
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()
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:
def _rebalance(self):
if len(self.lowers) - len(self.highers) > 1: