MCPcopy Create free account
hub / github.com/apache/arrow / ThreadUnsafeMemoizer

Class ThreadUnsafeMemoizer

cpp/src/arrow/util/cache_internal.h:147–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145
146template <typename Key, typename Value, typename Cache, typename Func>
147struct ThreadUnsafeMemoizer {
148 using RetType = const Value&;
149
150 template <typename F>
151 ThreadUnsafeMemoizer(F&& func, int32_t cache_capacity)
152 : func_(std::forward<F>(func)), cache_(cache_capacity) {}
153
154 const Value& operator()(const Key& key) {
155 const Value* value_ptr;
156 value_ptr = cache_.Find(key);
157 if (ARROW_PREDICT_TRUE(value_ptr != nullptr)) {
158 return *value_ptr;
159 }
160 return *cache_.Replace(key, func_(key)).second;
161 }
162
163 private:
164 Func func_;
165 Cache cache_;
166};
167
168template <template <typename...> class Cache, template <typename...> class MemoizerType,
169 typename Key, typename Func>

Callers

nothing calls this directly

Calls 2

FindMethod · 0.45
ReplaceMethod · 0.45

Tested by

no test coverage detected