36#include <gtest/gtest.h>
57 static bool should_throw;
60 explicit Throwing_Copy(
int v) :
value(v) {}
64 throw std::runtime_error(
"Throwing_Copy: copy failed");
66 Throwing_Copy(Throwing_Copy &&) =
default;
67 Throwing_Copy &operator=(
const Throwing_Copy &) =
default;
68 Throwing_Copy &operator=(Throwing_Copy &&) =
default;
71 bool Throwing_Copy::should_throw =
false;
100 bool saw =
m.with_value(
"alpha", [](
const std::unique_ptr<int> &p)
116 auto v =
m.find_copy(
"alpha");
124 m.insert_or_assign(
"alpha", 1);
126 m.insert_or_assign(
"alpha", 2);
147 EXPECT_TRUE(
m.with_value(
"alpha", [&](
const int &v) { seen = v; }));
151 EXPECT_FALSE(
m.with_value(
"missing", [&](
const int &) { called = true; }));
159 EXPECT_TRUE(
m.with_value_mut(
"alpha", [](
int &v) { v += 5; }));
162 EXPECT_FALSE(
m.with_value_mut(
"missing", [](
int &v) { v = 999; }));
168 for (
int i = 0; i < 100; ++i)
169 m.
insert(
"key" + std::to_string(i), i);
183 auto snap =
m.snapshot();
187 m.insert_or_assign(
"alpha", 999);
190 std::map<std::string, int>
as_map;
191 for (
const auto &entry :
snap)
201 Throwing_Copy
value(1);
202 Throwing_Copy::should_throw =
false;
205 Throwing_Copy::should_throw =
true;
206 Throwing_Copy
other(2);
208 Throwing_Copy::should_throw =
false;
221 constexpr size_t shards = 16;
226 for (
int i = 0; i < 200; ++i)
228 const int key =
static_cast<int>(idx) * 1000 + i;
248 const int key = base + i;
251 auto v =
m.find_copy(key);
258 const int key = base + i;
259 EXPECT_TRUE(
m.with_value_mut(key, [](
int &v) { v *= 2; }));
273 auto v =
m.find_copy(key);
287 4000, 0xBADC0FFEu, 200,
289 Trace_Operation_Kind::insert,
290 Trace_Operation_Kind::erase,
291 Trace_Operation_Kind::contains
294 std::map<size_t, size_t> reference;
301 case Trace_Operation_Kind::insert:
302 return ref.emplace(op.key, op.value).second;
303 case Trace_Operation_Kind::erase:
304 return ref.
erase(op.key) != 0;
305 case Trace_Operation_Kind::contains:
306 return ref.find(op.key) != ref.end();
316 case Trace_Operation_Kind::insert:
317 return s.
insert(op.key, op.value);
318 case Trace_Operation_Kind::erase:
319 return s.
erase(op.key);
320 case Trace_Operation_Kind::contains:
327 for (
size_t i = 0; i <
trace.size(); ++i)
335 for (
const auto &[key,
value] : reference)
337 auto v =
subject.find_copy(key);
338 ASSERT_TRUE(v.has_value()) <<
"missing key " << key;
size_t size_t int32_t value
Sharded concurrent hash map: Shards independently-locked DynMapHashTable partitions,...
bool contains(const Key &key) const
Check whether key is present.
bool insert(const Key &key, const T &value)
Insert key with a copy of value, only if key is absent.
bool erase(const Key &key)
Remove key if present.
constexpr bool contains(const Key &key) const noexcept
Alias for has().
Minimal std::expected-style result type for C++20.
void emplace(Args &&...args)
Appends a new element into the container by constructing it in-place with the given args.
constexpr size_t size() const noexcept
Returns the number of entries in the table.
void clear()
Empties the container.
constexpr bool is_empty() const noexcept
Checks if the table is empty.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Reusable helpers for concurrent data-structure tests.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::vector< Trace_Operation > make_random_operation_trace(const size_t count, const uint32_t seed, const size_t key_range, const std::initializer_list< Trace_Operation_Kind > kinds={ Trace_Operation_Kind::insert, Trace_Operation_Kind::erase, Trace_Operation_Kind::contains })
Build a deterministic pseudo-random operation trace.
void run_workers(const size_t thread_count, Worker worker)
Launch thread_count workers with a deterministic simultaneous start, join every one of them,...
Main namespace for Aleph-w library functions.
One randomized operation trace entry.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Sharded concurrent hash map (Aleph::ConcurrentHashMap).