Template Function sequant::detail::memoize¶
Defined in File memoize.hpp
Function Documentation¶
-
template<typename Key, typename Value, typename ComputeFn>
const Value &sequant::detail::memoize(container::map<Key, std::optional<Value>> &cache, std::mutex &mutex, std::condition_variable &cv, const Key &key, ComputeFn &&compute_fn)¶ Thread-safe memoization helper for expensive computations. Uses a placeholder pattern: inserts nullopt first to signal “computing”, then fills in the value and notifies waiters.
- Template Parameters:
Key – The cache key type
Value – The cached value type
ComputeFn – Callable returning Value
- Parameters:
cache – The cache map (must use std::optional<Value> as values)
mutex – The mutex protecting the cache
cv – The condition variable for waiting
key – The key to look up/store
compute_fn – A callable that computes the value if not cached
- Returns:
Reference to the cached value