示例#1
0
 def memoized_version_of_f(*args):
     """Wrapper using memoization
     """
     res = simcache.get_key(args)
     if not res:
         res = decorated_func(*args)  # Call the real function
         simcache.set_key(args, res)
     return res
示例#2
0
 def memoized_version_of_f(*args):
     """Wrapper using memoization
     """
     res = simcache.get_key(args)
     if not res:
         res = decorated_func(*args)  # Call the real function
         simcache.set_key(args, res)
     return res
示例#3
0
 def memoized_version_of_func(n):
     """Wrapper using memoization
     """
     res = simcache.get_key(n)
     if not res:
         res = func_to_memoize(n)  # Call the real function
         simcache.set_key(n, res)
     return res
示例#4
0
 def memoized_version_of_func(n):
     """Wrapper using memoization
     """
     res = simcache.get_key(n)
     if not res:
         res = func_to_memoize(n)  # Call the real function
         simcache.set_key(n, res)
     return res
示例#5
0
def factorial(x):
    time.sleep(0.1)  # This sleep can not be removed!!
    if x < 2:
        return 1
    res = simcache.get_key(x - 1)
    if not res:
        res = factorial(x - 1)
        simcache.set_key(x - 1, res)
    return x * res
示例#6
0
def factorial(x):
    time.sleep(0.1)  # This sleep can not be removed!!
    if x < 2:
        return 1
    res = simcache.get_key(x - 1)
    if not res:
        res = factorial(x - 1)
        simcache.set_key(x - 1, res)
    return x * res
示例#7
0
def memoized_fibonacci(n):
    # Try to retrieve value from cache
    res = simcache.get_key(n)
    if not res:
        # If failed, call real fibonacci func
        print "Memoized fibonacci func, proceeding to call real func", real_fibonacci, n
        res = real_fibonacci(n)
        # Store real result
        simcache.set_key(n, res)
    return res
示例#8
0
def memoized_fibonacci(n):
    # Try to retrieve value from cache
    res = simcache.get_key(n)
    if not res:
        # If failed, call real fibonacci func
        print "Memoized fibonacci func, proceeding to call real func", real_fibonacci, n
        res = real_fibonacci(n)
        # Store real result
        simcache.set_key(n, res)
    return res
示例#9
0
def fibonacci(n):
    res = simcache.get_key(n)
    if not res:
        res = real_fibonacci(n)
        simcache.set_key(n, res)
    return res
示例#10
0
def fibonacci(n):
    res = simcache.get_key(n)
    if not res:
        res = real_fibonacci(n)
        simcache.set_key(n, res)
    return res