Last active
December 15, 2015 01:38
-
-
Save oehme/5180925 to your computer and use it in GitHub Desktop.
Memoized fibonacci method - Generated Java code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Memoize | |
public BigInteger fibonacci(final int n) { | |
try { | |
return fibonacci_cache.get(n); | |
} catch(Throwable e) { | |
throw Exceptions.sneakyThrow(e.getCause()); | |
} | |
} | |
private BigInteger fibonacci_init(final int n) { | |
-- fibonacci algorithm here -- | |
} | |
private LoadingCache<Integer,BigInteger> fibonacci_cache = CacheBuilder.newBuilder() | |
.build(new CacheLoader<Integer, BigInteger>() { | |
@Override | |
public BigInteger load(Integer key) throws Exception { | |
return fibonacci_init(key); | |
} | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment