Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Memoizer.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/Containers/Common.h"
5
7
8 /*
9 ********************************************************************************
10 ******************************** Cache::Memoizer *******************************
11 ********************************************************************************
12 */
13 template <typename RESULT, template <typename, typename> class CACHE, typename... ARGS>
14 Memoizer<RESULT, CACHE, ARGS...>::Memoizer (const function<RESULT (ARGS...)>& f, CACHE<tuple<ARGS...>, RESULT>&& cache)
15 : fFunction_{f}
16 , fCache_{forward<CACHE<tuple<ARGS...>, RESULT>> (cache)}
17 {
18 }
19 template <typename RESULT, template <typename, typename> class CACHE, typename... ARGS>
21 {
22 // Lookup the value in the cache, and if that fails, call fFunction_ (and add that to the cache)
23 return fCache_.LookupValue (make_tuple (args...), [&] (const tuple<ARGS...>& t) { return apply (fFunction_, t); });
24 }
25
26}
LRUCache implements a simple least-recently-used caching strategy, with optional hashing (of keys) to...
Definition LRUCache.h:94
nonvirtual VALUE LookupValue(typename Common::ArgByValueType< KEY > key, const function< VALUE(typename Common::ArgByValueType< KEY >)> &valueFetcher)
Definition LRUCache.inl:302
nonvirtual RESULT operator()(ARGS... args)
Definition Memoizer.inl:20
Memoizer(const function< RESULT(ARGS...)> &f, CACHE< tuple< ARGS... >, RESULT > &&cache=CACHE< tuple< ARGS... >, RESULT >{})
Definition Memoizer.inl:14