From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 12:53:47 +0000 (+0100) Subject: move max_exponent to be a property (max(self)) X-Git-Tag: div_pipeline~2162 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd63a4f5a785a96fd893abac7dd4e1ce6c943f85;p=soc.git move max_exponent to be a property (max(self)) replace if tests with assert (single lines each) remove self.max_exponent test on every element, use max(self) as property set-ify the incoming argument exponents and add zero explicitly to it pass that in to the set constructor, no need for accumulating in a temporary --- diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index 62ee8f5c..814ad06f 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -8,17 +8,16 @@ class LFSRPolynomial(set): """ implements a polynomial for use in LFSR """ def __init__(self, exponents=()): - self.max_exponent = 0 - elements = {0} # 0 is always required + exponents = set(exponents) + exponents.add(0) # must contain zero for e in exponents: - if not isinstance(e, int): - raise TypeError("exponent %s must be an integer" % repr(e)) - if e < 0: - raise ValueError("exponent %d must not be negative" % e) - self.max_exponent = max(e, self.max_exponent) - elements.add(e) # uniquifies additions (it's a set!) - - set.__init__(self, elements) + assert isinstance(e, int), TypeError("%s must be an int" % repr(e)) + assert (e >= 0), ValueError("%d must not be negative" % e) + set.__init__(self, exponents) + + @property + def max_exponent(self): + return max(self) # derived from set, so this returns the max exponent @property def exponents(self):