Stroika Library
3.0d16
Help-Home
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
6
namespace
Stroika::Foundation::Cache
{
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>
20
RESULT
Memoizer<RESULT, CACHE, ARGS...>::operator()
(
ARGS
...
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
}
Stroika::Foundation::Cache::LRUCache
LRUCache implements a simple least-recently-used caching strategy, with optional hashing (of keys) to...
Definition
LRUCache.h:94
Stroika::Foundation::Cache::LRUCache::LookupValue
nonvirtual VALUE LookupValue(typename Common::ArgByValueType< KEY > key, const function< VALUE(typename Common::ArgByValueType< KEY >)> &valueFetcher)
Definition
LRUCache.inl:302
Stroika::Foundation::Cache::Memoizer::operator()
nonvirtual RESULT operator()(ARGS... args)
Definition
Memoizer.inl:20
Stroika::Foundation::Cache::Memoizer::Memoizer
Memoizer(const function< RESULT(ARGS...)> &f, CACHE< tuple< ARGS... >, RESULT > &&cache=CACHE< tuple< ARGS... >, RESULT >{})
Definition
Memoizer.inl:14
Stroika::Foundation::Cache
Definition
BloomFilter.h:22
Library
Sources
Stroika
Foundation
Cache
Memoizer.inl
Generated by
1.9.8