Public Member Functions | |
def | __init__ |
def | type |
def | __str__ |
def | addString |
def | addValue |
def | verify |
Cache factor lists in a dictionary. Key is the value of the number. Value is the list of the numbers' factors (.
Definition at line 11 of file FactorCache.py.
def FactorCache::FactorCache::__init__ | ( | self, | ||
saver = None | ||||
) |
def FactorCache::FactorCache::__str__ | ( | self | ) |
Definition at line 27 of file FactorCache.py.
00027 : 00028 00029 answer = "" 00030 keys = self.sortedkeys( ) 00031 for key in keys: 00032 factors = self._dict[ key ] 00033 answer += "%s %s\n" % ( key, factors ) 00034 00035 if answer == "": 00036 answer = "<FactorCache.FactorCache instance>" 00037 00038 return answer 00039 def addString( self, line ):
def FactorCache::FactorCache::addString | ( | self, | ||
line | ||||
) |
Definition at line 40 of file FactorCache.py.
00040 : 00041 00042 tokens = re.split( "[()]+", line ) 00043 value = mpz( tokens[ 0 ] ) 00044 factors = Factors.FromString( tokens[ 1 ] ) 00045 self.addValue( value, factors, False ) 00046 def addValue( self, value, factors, saver = True ):
def FactorCache::FactorCache::addValue | ( | self, | ||
value, | ||||
factors, | ||||
saver = True | ||||
) |
Definition at line 47 of file FactorCache.py.
00047 : 00048 00049 if self.verify( value, factors ): 00050 if not self._dict.has_key( value ): 00051 self.at_put( value, factors ) 00052 if saver: 00053 globals.Saver.newFactor( ) 00054 00055 return 00056 def verify( self, value, factors ):
def FactorCache::FactorCache::type | ( | self | ) |
def FactorCache::FactorCache::verify | ( | self, | ||
value, | ||||
factors | ||||
) |
Definition at line 57 of file FactorCache.py.
00057 : 00058 00059 magnitude = factors.magnitude( ) 00060 if value == magnitude: 00061 return True 00062 else: 00063 print "FactorCache error:" 00064 print " %s" % value 00065 print " %s" % factors 00066 pydb.debugger( ) 00067 return False 00068 if __name__ == '__main__':