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

Method Replace

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

Source from the content-addressed store, hash-verified

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