clang-tools 20.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 147 of file Threading.h.
|
inline |
Definition at line 152 of file Threading.h.
|
inline |
Definition at line 155 of file Threading.h.