clang-tools
15.0.0git
|
Memoize is a cache to store and reuse computation results based on a key. More...
#include <Threading.h>
Public Member Functions | |
Memoize () | |
template<typename T , typename Func > | |
Container::mapped_type | get (T &&Key, Func Compute) const |
Memoize is a cache to store and reuse computation results based on a key.
Memoize<DenseMap<int, bool>> PrimeCache; for (int I : RepetitiveNumbers) if (PrimeCache.get(I, [&] { return expensiveIsPrime(I); })) llvm::errs() << "Prime: " << I << "\n";
The computation will only be run once for each key. This class is threadsafe. Concurrent calls for the same key may run the computation multiple times, but each call will return the same result.
Definition at line 146 of file Threading.h.
|
inline |
Definition at line 151 of file Threading.h.
|
inline |
Definition at line 154 of file Threading.h.