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

Method Replace

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

Source from the content-addressed store, hash-verified

71
72 template <typename K, typename V>
73 std::pair<bool, Value*> Replace(K&& key, V&& value) {
74 // Try to insert temporary iterator
75 auto pair = map_.emplace(std::forward<K>(key), ListIt{});
76 const auto it = pair.first;
77 const bool inserted = pair.second;
78 if (inserted) {
79 // Inserted => push item at front of the list, and update iterator
80 items_.push_front(Item{&it->first, std::forward<V>(value)});
81 it->second = items_.begin();
82 // Did we exceed the cache capacity? If so, remove least recently used item
83 if (static_cast<int32_t>(items_.size()) > capacity_) {
84 const bool erased = map_.erase(*items_.back().key);
85 ARROW_DCHECK(erased);
86 ARROW_UNUSED(erased);
87 items_.pop_back();
88 }
89 return {true, &it->second->value};
90 } else {
91 // Already exists => move item at front of the list, and update value
92 auto list_it = it->second;
93 items_.splice(items_.begin(), items_, list_it);
94 list_it->value = std::forward<V>(value);
95 return {false, &list_it->value};
96 }
97 }
98
99 private:
100 struct Item {

Callers 3

BenchmarkCacheLookupsFunction · 0.45
operator()Method · 0.45

Calls 3

backMethod · 0.80
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected