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