This is an automated email from the ASF dual-hosted git repository.
pitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 2434310f1d6 GH-51367: [C++] Remove unused arrow::internal::LruCache
and its tests/benchmarks (#51384)
2434310f1d6 is described below
commit 2434310f1d600b0ae68cec3a32cba3ebc853df6a
Author: Basant_Jamwal <[email protected]>
AuthorDate: Mon Nov 9 21:23:13 2026 +0530
GH-51367: [C++] Remove unused arrow::internal::LruCache and its
tests/benchmarks (#51384)
Closes #51367
### Rationale for this change
No code within Arrow uses `arrow::internal::LruCache`. Per discussion in
#51328 (review comment r4027861697), removing this dead code along with
its tests and benchmarks.
### What changes are included in this PR?
- Removed cpp/src/arrow/util/cache_internal.h (LruCache, MemoizeLru,
MemoizeLruThreadUnsafe — all unused outside this file and its tests)
- Removed cpp/src/arrow/util/cache_test.cc
- Removed cpp/src/arrow/util/cache_benchmark.cc
- Removed corresponding entries from cpp/src/arrow/util/CMakeLists.txt
Verified via `git grep` across cpp/ that nothing else references this
code (gandiva's separate LRU cache in cpp/src/gandiva/lru_cache.h is
unrelated and untouched).
Supersedes #51371, which was opened with an empty diff due to a branch
mix-up.
### Are these changes tested?
Pure removal of unused code; no new tests needed. Relying on CI to
validate the build/test suite still passes.
### Are there any user-facing changes?
No.
### Was AI used for this PR?
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
Authored-by: Basant_Jamwal <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
cpp/src/arrow/util/CMakeLists.txt | 2 -
cpp/src/arrow/util/cache_benchmark.cc | 147 -----------------
cpp/src/arrow/util/cache_internal.h | 208 ------------------------
cpp/src/arrow/util/cache_test.cc | 293 ----------------------------------
cpp/src/arrow/util/meson.build | 2 -
5 files changed, 652 deletions(-)
diff --git a/cpp/src/arrow/util/CMakeLists.txt
b/cpp/src/arrow/util/CMakeLists.txt
index 5bce8549cf3..cb516a4d84b 100644
--- a/cpp/src/arrow/util/CMakeLists.txt
+++ b/cpp/src/arrow/util/CMakeLists.txt
@@ -50,7 +50,6 @@ add_arrow_test(utility-test
base64_test.cc
byte_size_test.cc
byte_stream_split_test.cc
- cache_test.cc
checked_cast_test.cc
compression_test.cc
decimal_test.cc
@@ -132,7 +131,6 @@ add_arrow_benchmark(bit_block_counter_benchmark)
add_arrow_benchmark(bit_util_benchmark)
add_arrow_benchmark(bitmap_reader_benchmark)
add_arrow_benchmark(bpacking_benchmark)
-add_arrow_benchmark(cache_benchmark)
add_arrow_benchmark(compression_benchmark)
add_arrow_benchmark(decimal_benchmark)
add_arrow_benchmark(hashing_benchmark)
diff --git a/cpp/src/arrow/util/cache_benchmark.cc
b/cpp/src/arrow/util/cache_benchmark.cc
deleted file mode 100644
index 071367d8ec6..00000000000
--- a/cpp/src/arrow/util/cache_benchmark.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "benchmark/benchmark.h"
-
-#include <cstdint>
-#include <string>
-#include <vector>
-
-#include "arrow/array.h"
-#include "arrow/testing/random.h"
-#include "arrow/util/cache_internal.h"
-#include "arrow/util/checked_cast.h"
-#include "arrow/util/logging.h"
-#include "arrow/util/macros.h"
-
-namespace arrow {
-namespace internal {
-
-static constexpr int32_t kCacheSize = 100;
-static constexpr int32_t kSmallKeyLength = 8;
-static constexpr int32_t kLargeKeyLength = 64;
-static constexpr int32_t kSmallValueLength = 16;
-static constexpr int32_t kLargeValueLength = 1024;
-
-static std::vector<std::string> MakeStrings(int64_t nvalues, int64_t
min_length,
- int64_t max_length) {
- auto rng = ::arrow::random::RandomArrayGenerator(42);
- auto arr = checked_pointer_cast<StringArray>(rng.String(
- nvalues, static_cast<int32_t>(min_length),
static_cast<int32_t>(max_length)));
- std::vector<std::string> vec(nvalues);
- for (int64_t i = 0; i < nvalues; ++i) {
- vec[i] = arr->GetString(i);
- }
- return vec;
-}
-
-static std::vector<std::string> MakeStrings(int64_t nvalues, int64_t length) {
- return MakeStrings(nvalues, length, length);
-}
-
-template <typename Cache, typename Key, typename Value>
-static void BenchmarkCacheLookups(benchmark::State& state, const
std::vector<Key>& keys,
- const std::vector<Value>& values) {
- const int32_t nitems = static_cast<int32_t>(keys.size());
- Cache cache(nitems);
- for (int32_t i = 0; i < nitems; ++i) {
- cache.Replace(keys[i], values[i]);
- }
-
- for (auto _ : state) {
- int64_t nfinds = 0;
- for (const auto& key : keys) {
- nfinds += (cache.Find(key) != nullptr);
- }
- benchmark::DoNotOptimize(nfinds);
- ARROW_CHECK_EQ(nfinds, nitems);
- }
- state.SetItemsProcessed(state.iterations() * nitems);
-}
-
-static void LruCacheLookup(benchmark::State& state) {
- const auto keys = MakeStrings(kCacheSize, state.range(0));
- const auto values = MakeStrings(kCacheSize, state.range(1));
- BenchmarkCacheLookups<LruCache<std::string, std::string>>(state, keys,
values);
-}
-
-static void SetCacheArgs(benchmark::internal::Benchmark* bench) {
- bench->Args({kSmallKeyLength, kSmallValueLength});
- bench->Args({kSmallKeyLength, kLargeValueLength});
- bench->Args({kLargeKeyLength, kSmallValueLength});
- bench->Args({kLargeKeyLength, kLargeValueLength});
-}
-
-BENCHMARK(LruCacheLookup)->Apply(SetCacheArgs);
-
-struct Callable {
- explicit Callable(std::vector<std::string> values)
- : index_(0), values_(std::move(values)) {}
-
- std::string operator()(const std::string& key) {
- // Return a value unrelated to the key
- if (++index_ >= static_cast<int64_t>(values_.size())) {
- index_ = 0;
- }
- return values_[index_];
- }
-
- private:
- int64_t index_;
- std::vector<std::string> values_;
-};
-
-template <typename Memoized>
-static void BenchmarkMemoize(benchmark::State& state, Memoized&& mem,
- const std::vector<std::string>& keys) {
- // Prime memoization cache
- for (const auto& key : keys) {
- mem(key);
- }
-
- for (auto _ : state) {
- int64_t nbytes = 0;
- for (const auto& key : keys) {
- nbytes += static_cast<int64_t>(mem(key).length());
- }
- benchmark::DoNotOptimize(nbytes);
- }
- state.SetItemsProcessed(state.iterations() * keys.size());
-}
-
-static void MemoizeLruCached(benchmark::State& state) {
- const auto keys = MakeStrings(kCacheSize, state.range(0));
- const auto values = MakeStrings(kCacheSize, state.range(1));
- auto mem = MemoizeLru<std::string>(Callable(values), kCacheSize);
- BenchmarkMemoize(state, mem, keys);
-}
-
-static void MemoizeLruCachedThreadUnsafe(benchmark::State& state) {
- const auto keys = MakeStrings(kCacheSize, state.range(0));
- const auto values = MakeStrings(kCacheSize, state.range(1));
- // Emulate recommended usage of MemoizeLruCachedThreadUnsafe
- // (the compiler is probably able to cache the TLS-looked up value, though)
- thread_local auto mem =
- MemoizeLruThreadUnsafe<std::string>(Callable(values), kCacheSize);
- BenchmarkMemoize(state, mem, keys);
-}
-
-BENCHMARK(MemoizeLruCached)->Apply(SetCacheArgs);
-BENCHMARK(MemoizeLruCachedThreadUnsafe)->Apply(SetCacheArgs);
-
-} // namespace internal
-} // namespace arrow
diff --git a/cpp/src/arrow/util/cache_internal.h
b/cpp/src/arrow/util/cache_internal.h
deleted file mode 100644
index 6c65712060f..00000000000
--- a/cpp/src/arrow/util/cache_internal.h
+++ /dev/null
@@ -1,208 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include <functional>
-#include <list>
-#include <memory>
-#include <mutex>
-#include <type_traits>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-#include "arrow/util/logging.h"
-#include "arrow/util/macros.h"
-
-namespace arrow {
-namespace internal {
-
-// A LRU (Least recently used) replacement cache
-template <typename Key, typename Value>
-class LruCache {
- public:
- explicit LruCache(int32_t capacity) : capacity_(capacity) {
- // The map size can temporarily exceed the cache capacity, see Replace()
- map_.reserve(capacity_ + 1);
- }
-
- ARROW_DISALLOW_COPY_AND_ASSIGN(LruCache);
- ARROW_DEFAULT_MOVE_AND_ASSIGN(LruCache);
-
- void Clear() {
- items_.clear();
- map_.clear();
- // The C++ spec doesn't tell whether map_.clear() will shrink the map
capacity
- map_.reserve(capacity_ + 1);
- }
-
- int32_t size() const {
- ARROW_DCHECK_EQ(items_.size(), map_.size());
- return static_cast<int32_t>(items_.size());
- }
-
- template <typename K>
- Value* Find(K&& key) {
- const auto it = map_.find(key);
- if (it == map_.end()) {
- return nullptr;
- } else {
- // Found => move item at front of the list
- auto list_it = it->second;
- items_.splice(items_.begin(), items_, list_it);
- return &list_it->value;
- }
- }
-
- template <typename K, typename V>
- std::pair<bool, Value*> Replace(K&& key, V&& value) {
- // Try to insert temporary iterator
- auto pair = map_.emplace(std::forward<K>(key), ListIt{});
- const auto it = pair.first;
- const bool inserted = pair.second;
- if (inserted) {
- // Inserted => push item at front of the list, and update iterator
- items_.push_front(Item{&it->first, std::forward<V>(value)});
- it->second = items_.begin();
- // Did we exceed the cache capacity? If so, remove least recently used
item
- if (static_cast<int32_t>(items_.size()) > capacity_) {
- const bool erased = map_.erase(*items_.back().key);
- ARROW_DCHECK(erased);
- ARROW_UNUSED(erased);
- items_.pop_back();
- }
- return {true, &it->second->value};
- } else {
- // Already exists => move item at front of the list, and update value
- auto list_it = it->second;
- items_.splice(items_.begin(), items_, list_it);
- list_it->value = std::forward<V>(value);
- return {false, &list_it->value};
- }
- }
-
- private:
- struct Item {
- // Pointer to the key inside the unordered_map
- const Key* key;
- Value value;
- };
- using List = std::list<Item>;
- using ListIt = typename List::iterator;
-
- const int32_t capacity_;
- // In most to least recently used order
- std::list<Item> items_;
- std::unordered_map<Key, ListIt> map_;
-};
-
-namespace detail {
-
-template <typename Key, typename Value, typename Cache, typename Func>
-struct ThreadSafeMemoizer {
- using RetType = Value;
-
- template <typename F>
- ThreadSafeMemoizer(F&& func, int32_t cache_capacity)
- : func_(std::forward<F>(func)), cache_(cache_capacity) {}
-
- // The memoizer can't return a pointer to the cached value, because
- // the cache entry may be evicted by another thread.
-
- Value operator()(const Key& key) {
- std::unique_lock<std::mutex> lock(mutex_);
- const Value* value_ptr;
- value_ptr = cache_.Find(key);
- if (ARROW_PREDICT_TRUE(value_ptr != nullptr)) {
- return *value_ptr;
- }
- lock.unlock();
- Value v = func_(key);
- lock.lock();
- return *cache_.Replace(key, std::move(v)).second;
- }
-
- private:
- std::mutex mutex_;
- Func func_;
- Cache cache_;
-};
-
-template <typename Key, typename Value, typename Cache, typename Func>
-struct ThreadUnsafeMemoizer {
- using RetType = const Value&;
-
- template <typename F>
- ThreadUnsafeMemoizer(F&& func, int32_t cache_capacity)
- : func_(std::forward<F>(func)), cache_(cache_capacity) {}
-
- const Value& operator()(const Key& key) {
- const Value* value_ptr;
- value_ptr = cache_.Find(key);
- if (ARROW_PREDICT_TRUE(value_ptr != nullptr)) {
- return *value_ptr;
- }
- return *cache_.Replace(key, func_(key)).second;
- }
-
- private:
- Func func_;
- Cache cache_;
-};
-
-template <template <typename...> class Cache, template <typename...> class
MemoizerType,
- typename Key, typename Func>
-static auto Memoize(Func&& func, int32_t cache_capacity) {
- using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
- using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
- using RetType = typename Memoizer::RetType;
-
- // std::function<> requires copy constructibility
- struct {
- RetType operator()(const Key& key) const { return (*memoized_)(key); }
- std::shared_ptr<Memoizer> memoized_;
- } shared_memoized = {
- std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
-
- return std::function<RetType(const Key&)>(std::move(shared_memoized));
-}
-
-} // namespace detail
-
-// Apply a LRU memoization cache to a callable.
-// `Key` is the type of the callable's (single) argument.
-template <typename Key, typename Func>
- requires std::is_invocable_v<Func, const Key&>
-static auto MemoizeLru(Func&& func, int32_t cache_capacity) {
- return detail::Memoize<LruCache, detail::ThreadSafeMemoizer, Key>(
- std::forward<Func>(func), cache_capacity);
-}
-
-// Like MemoizeLru, but not thread-safe. This version allows for much faster
-// lookups (more than 2x faster), but you'll have to manage thread safety
yourself.
-// A recommended usage is to declare per-thread caches using `thread_local`
-// (see cache_benchmark.cc).
-template <typename Key, typename Func>
- requires std::is_invocable_v<Func, const Key&>
-static auto MemoizeLruThreadUnsafe(Func&& func, int32_t cache_capacity) {
- return detail::Memoize<LruCache, detail::ThreadUnsafeMemoizer, Key>(
- std::forward<Func>(func), cache_capacity);
-}
-
-} // namespace internal
-} // namespace arrow
diff --git a/cpp/src/arrow/util/cache_test.cc b/cpp/src/arrow/util/cache_test.cc
deleted file mode 100644
index d009806ab34..00000000000
--- a/cpp/src/arrow/util/cache_test.cc
+++ /dev/null
@@ -1,293 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include <atomic>
-#include <cstdint>
-#include <functional>
-#include <ostream>
-#include <string>
-#include <thread>
-
-#include <gtest/gtest.h>
-
-#include "arrow/testing/gtest_util.h"
-#include "arrow/util/cache_internal.h"
-#include "arrow/util/config.h"
-
-namespace arrow {
-namespace internal {
-
-template <typename K1, typename V1, typename K2, typename V2>
-void AssertPairsEqual(std::pair<K1, V1> left, std::pair<K2, V2> right) {
- ASSERT_EQ(left.first, right.first);
- ASSERT_EQ(left.second, right.second);
-}
-
-class IntValue {
- public:
- explicit IntValue(int value = 0) : value_(std::make_shared<int>(value)) {}
-
- IntValue(const IntValue&) = default;
- IntValue(IntValue&&) = default;
- IntValue& operator=(const IntValue&) = default;
- IntValue& operator=(IntValue&&) = default;
-
- int value() const { return *value_; }
-
- bool operator==(const IntValue& other) const { return *value_ ==
*other.value_; }
- bool operator!=(const IntValue& other) const { return *value_ !=
*other.value_; }
-
- friend std::ostream& operator<<(std::ostream& os, IntValue v) {
- os << "IntValue{" << *v.value_ << "}";
- return os;
- }
-
- private:
- // The shared_ptr makes it easier to detect lifetime bugs
- std::shared_ptr<int> value_;
-};
-
-template <typename Value>
-Value Identity(Value&& v) {
- return std::forward<Value>(v);
-}
-
-class TestLruCache : public ::testing::Test {
- public:
- using K = std::string;
- using V = IntValue;
- using Cache = LruCache<K, V>;
-
- K MakeKey(int num) { return std::to_string(num); }
-
- const V* Find(Cache* cache, int num) { return cache->Find(MakeKey(num)); }
-
- bool Replace(Cache* cache, int num, int value_num) {
- auto pair = cache->Replace(MakeKey(num), V{value_num});
- EXPECT_NE(pair.second, nullptr);
- EXPECT_EQ(*pair.second, V{value_num});
- return pair.first;
- }
-};
-
-TEST_F(TestLruCache, Basics) {
- Cache cache(10);
-
- using namespace std::placeholders; // NOLINT [build/namespaces]
- auto Replace = std::bind(&TestLruCache::Replace, this, &cache, _1, _2);
- auto Find = std::bind(&TestLruCache::Find, this, &cache, _1);
-
- ASSERT_EQ(cache.size(), 0);
- ASSERT_EQ(Find(100), nullptr);
-
- // Insertions
- ASSERT_TRUE(Replace(100, 100));
- ASSERT_TRUE(Replace(101, 101));
- ASSERT_TRUE(Replace(102, 102));
- ASSERT_EQ(cache.size(), 3);
- ASSERT_EQ(*Find(100), V{100});
- ASSERT_EQ(*Find(101), V{101});
- ASSERT_EQ(*Find(102), V{102});
-
- // Replacements
- ASSERT_FALSE(Replace(100, -100));
- ASSERT_FALSE(Replace(101, -101));
- ASSERT_FALSE(Replace(102, -102));
- ASSERT_EQ(cache.size(), 3);
- ASSERT_EQ(*Find(100), V{-100});
- ASSERT_EQ(*Find(101), V{-101});
- ASSERT_EQ(*Find(102), V{-102});
-
- ASSERT_EQ(cache.size(), 3);
- cache.Clear();
- ASSERT_EQ(cache.size(), 0);
-}
-
-TEST_F(TestLruCache, Eviction) {
- Cache cache(5);
-
- using namespace std::placeholders; // NOLINT [build/namespaces]
- auto Replace = std::bind(&TestLruCache::Replace, this, &cache, _1, _2);
- auto Find = std::bind(&TestLruCache::Find, this, &cache, _1);
-
- for (int i = 100; i < 105; ++i) {
- ASSERT_TRUE(Replace(i, i));
- }
- ASSERT_EQ(cache.size(), 5);
-
- // Access keys in a specific order
- for (int i : {102, 103, 101, 104, 100}) {
- ASSERT_EQ(*Find(i), V{i});
- }
- // Insert more entries
- ASSERT_TRUE(Replace(105, 105));
- ASSERT_TRUE(Replace(106, 106));
- // The least recently used keys were evicted
- ASSERT_EQ(Find(102), nullptr);
- ASSERT_EQ(Find(103), nullptr);
- for (int i : {100, 101, 104, 105, 106}) {
- ASSERT_EQ(*Find(i), V{i});
- }
-
- // Alternate insertions and replacements
- // MRU = [106, 105, 104, 101, 100]
- ASSERT_FALSE(Replace(106, -106));
- // MRU = [106, 105, 104, 101, 100]
- ASSERT_FALSE(Replace(100, -100));
- // MRU = [100, 106, 105, 104, 101]
- ASSERT_FALSE(Replace(104, -104));
- // MRU = [104, 100, 106, 105, 101]
- ASSERT_TRUE(Replace(102, -102));
- // MRU = [102, 104, 100, 106, 105]
- ASSERT_TRUE(Replace(101, -101));
- // MRU = [101, 102, 104, 100, 106]
- for (int i : {101, 102, 104, 100, 106}) {
- ASSERT_EQ(*Find(i), V{-i});
- }
- ASSERT_EQ(Find(103), nullptr);
- ASSERT_EQ(Find(105), nullptr);
-
- // MRU = [106, 100, 104, 102, 101]
- ASSERT_TRUE(Replace(103, -103));
- // MRU = [103, 106, 100, 104, 102]
- ASSERT_TRUE(Replace(105, -105));
- // MRU = [105, 103, 106, 100, 104]
- for (int i : {105, 103, 106, 100, 104}) {
- ASSERT_EQ(*Find(i), V{-i});
- }
- ASSERT_EQ(Find(101), nullptr);
- ASSERT_EQ(Find(102), nullptr);
-}
-
-struct Callable {
- std::atomic<int> num_calls{0};
-
- IntValue operator()(const std::string& s) {
- ++num_calls;
- return IntValue{std::stoi(s)};
- }
-};
-
-struct MemoizeLruFactory {
- template <typename Func>
- auto operator()(Func&& func, int32_t capacity) {
- return MemoizeLru<std::string>(std::forward<Func>(func), capacity);
- }
-};
-
-struct MemoizeLruThreadUnsafeFactory {
- template <typename Func>
- auto operator()(Func&& func, int32_t capacity) {
- return MemoizeLruThreadUnsafe<std::string>(std::forward<Func>(func),
capacity);
- }
-};
-
-template <typename T>
-class TestMemoizeLru : public ::testing::Test {
- public:
- using K = std::string;
- using V = IntValue;
- using MemoizerFactory = T;
-
- K MakeKey(int num) { return std::to_string(num); }
-
- void TestBasics() {
- using V = IntValue;
- Callable c;
-
- auto mem = factory_(c, 5);
-
- // Cache fills
- for (int i = 0; i < 5; ++i) {
- ASSERT_EQ(mem(MakeKey(i)), V{i});
- }
- ASSERT_EQ(c.num_calls, 5);
-
- // Cache hits
- for (int i : {1, 3, 4, 0, 2}) {
- ASSERT_EQ(mem(MakeKey(i)), V{i});
- }
- ASSERT_EQ(c.num_calls, 5);
-
- // Calling with other inputs will cause evictions
- for (int i = 5; i < 8; ++i) {
- ASSERT_EQ(mem(MakeKey(i)), V{i});
- }
- ASSERT_EQ(c.num_calls, 8);
- // Hits
- for (int i : {0, 2, 5, 6, 7}) {
- ASSERT_EQ(mem(MakeKey(i)), V{i});
- }
- ASSERT_EQ(c.num_calls, 8);
- // Misses
- for (int i : {1, 3, 4}) {
- ASSERT_EQ(mem(MakeKey(i)), V{i});
- }
- ASSERT_EQ(c.num_calls, 11);
- }
-
- protected:
- MemoizerFactory factory_;
-};
-
-using MemoizeLruTestTypes =
- ::testing::Types<MemoizeLruFactory, MemoizeLruThreadUnsafeFactory>;
-
-TYPED_TEST_SUITE(TestMemoizeLru, MemoizeLruTestTypes);
-
-TYPED_TEST(TestMemoizeLru, Basics) { this->TestBasics(); }
-
-class TestMemoizeLruThreadSafe : public TestMemoizeLru<MemoizeLruFactory> {};
-
-TEST_F(TestMemoizeLruThreadSafe, Threads) {
-#ifndef ARROW_ENABLE_THREADING
- GTEST_SKIP() << "Test requires threading support";
-#endif
-
- using V = IntValue;
- Callable c;
-
- auto mem = this->factory_(c, 15);
- const int n_threads = 4;
-#ifdef ARROW_VALGRIND
- const int n_iters = 10;
-#else
- const int n_iters = 100;
-#endif
-
- auto thread_func = [&]() {
- for (int i = 0; i < n_iters; ++i) {
- const V& orig_value = mem("1");
- // Ensure that some replacements are going on
- // (# distinct keys > cache size)
- for (int j = 0; j < 30; ++j) {
- ASSERT_EQ(mem(std::to_string(j)), V{j});
- }
- ASSERT_EQ(orig_value, V{1});
- }
- };
- std::vector<std::thread> threads;
- for (int i = 0; i < n_threads; ++i) {
- threads.emplace_back(thread_func);
- }
- for (auto& thread : threads) {
- thread.join();
- }
-}
-
-} // namespace internal
-} // namespace arrow
diff --git a/cpp/src/arrow/util/meson.build b/cpp/src/arrow/util/meson.build
index 7dd37922090..96cbcfa2f5e 100644
--- a/cpp/src/arrow/util/meson.build
+++ b/cpp/src/arrow/util/meson.build
@@ -187,7 +187,6 @@ utility_test_srcs = [
'atfork_test.cc',
'byte_size_test.cc',
'byte_stream_split_test.cc',
- 'cache_test.cc',
'checked_cast_test.cc',
'compression_test.cc',
'decimal_test.cc',
@@ -293,7 +292,6 @@ util_benchmarks = [
'bit_util',
'bitmap_reader',
'bpacking',
- 'cache',
'compression',
'decimal',
'hashing',