def cont_test(): nlazy = evalcache.Memoize(algo=hashlib.sha512) s = {} for i in range(0, 100): for j in range(0, 100): h = nlazy((i, j)).__lazyhash__ if h in s: print("FAULT:", (i, j), "equal", s[h]) return s[h] = (i, j)
#!/usr/bin/env python3 import evalcache import hashlib lazy = evalcache.Memoize(algo = hashlib.sha512) print(lazy((11,0)).__lazyhash__) print(lazy((1,10)).__lazyhash__) print(lazy([11,0]).__lazyhash__) print(lazy([1,10]).__lazyhash__) print()
#!/usr/bin/python3 import sys sys.path.insert(0, "..") import evalcache # lazy = evalcache.Lazy(cache = evalcache.DirCache(".evalcache"), encache=False, decache=False) lazy = evalcache.Memoize() @lazy def foo(): print("foo") return 33 a = foo() b = foo() print(a) print(b)
#!/usr/bin/python3 import sys sys.path.insert(0, "..") import evalcache import math # lazy = evalcache.Memoize(onplace = False, diag=True, print_invokes=True, print_values=True) lazy = evalcache.Memoize(onplace=True) @lazy def fib(n): if n < 2: return n return fib(n - 1) + fib(n - 2) # a = fib(10) # b = fib(8) # print(fib(20)) for i in range(0, 100): print(fib(i))
#!/usr/bin/python3 # coding:utf-8 import evalcache import evalcache.dircache import shutil import os dircache_path = ".evalcache" dircache_path2 = ".evalcache2" lazy = evalcache.Lazy(cache=evalcache.dircache.DirCache(dircache_path)) memoize = evalcache.Memoize(onplace=False) onplace_memoize = evalcache.Memoize(onplace=True) def clean(): for path in os.listdir(dircache_path): os.remove("{}/{}".format(dircache_path, path)) lazy.cache.files = set() def full_clean(): #shutil.rmtree(dircache_path, ignore_errors=False, onerror=None) shutil.rmtree(dircache_path2, ignore_errors=False, onerror=None) def clean_memoize(): memoize.cache = {}