Пример #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