Class MemoizationDictionary<TInput, TOutput>
Encapsulates a memoization dictionary for caching outputs of a function that could be expensive to compute.
public sealed class MemoizationDictionary<TInput, TOutput> where TInput : notnull
Type Parameters
TInputTOutput
- Inheritance
-
MemoizationDictionary<TInput, TOutput>
- Inherited Members
- Extension Methods
Constructors
MemoizationDictionary(Func<TInput, TOutput>, int)
Encapsulates a memoization dictionary for caching outputs of a function that could be expensive to compute.
public MemoizationDictionary(Func<TInput, TOutput> func, int capacity = 64)
Parameters
funcFunc<TInput, TOutput>The function that computes the outputs.
capacityintThe initial capacity of the dictionary.
Methods
Clear()
Clears the cache.
public void Clear()
Get(TInput)
Gets the value of the given input. If the value has not been computed before, it is computed and stored into the dictionary for future retrievals. Otherwise, it's fetched directly from the dictionary.
public TOutput Get(TInput input)
Parameters
inputTInputThe input to the function.
Returns
- TOutput
The output of the function that was initialized, either cached or computed.