Last active
May 17, 2016 21:13
-
-
Save acoffman/1201988 to your computer and use it in GitHub Desktop.
memoization
This file contains hidden or 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
public static class Memoization { | |
public static Func<T,K> MemoizeFunction<T, K>(this Func<T, K> function) { | |
var table = new Dictionary<T, K>(); | |
return (args) => { | |
if (table.ContainsKey(args)) return table[args]; | |
var result = function(args); | |
table[args] = result; | |
return result; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment