53 std::cout <<
"[1] Single-threaded insert/find/erase walkthrough\n";
60 counters.with_value_mut(
"visits", [](
int &v) { v += 3; });
61 counters.insert_or_assign(
"errors", 1);
63 std::cout <<
"visits: " << *
counters.find_copy(
"visits") <<
" (expect 3)\n";
64 std::cout <<
"errors: " << *
counters.find_copy(
"errors") <<
" (expect 1)\n";
65 std::cout <<
"contains 'timeouts': " << std::boolalpha
66 <<
counters.contains(
"timeouts") <<
" (expect false)\n\n";
71 std::cout <<
"[2] Eight worker threads sharing one sharded map\n";
81 std::atomic<bool> start{
false};
82 std::vector<std::thread> workers;
85 workers.emplace_back([&,
w]
87 while (not start.load(std::memory_order_acquire))
89 const int base = w * keys_per_worker;
90 for (int i = 0; i < keys_per_worker; ++i)
91 map.insert(base + i, i);
94 start.store(
true, std::memory_order_release);
95 for (
auto &
w : workers)
98 std::cout <<
"Total entries: " << map.
size() <<
" (expect "
101 auto snapshot = map.snapshot();
102 std::cout <<
"Snapshot size: " << snapshot.
size()
103 <<
" (an independent copy, unaffected by later mutations)\n\n";
109 std::cout <<
"\n=== Aleph::ConcurrentHashMap: sharded concurrent map ===\n\n";
114 std::cout <<
"Done.\n";
Sharded concurrent hash map: Shards independently-locked DynMapHashTable partitions,...
size_t size() const
Return the total number of entries across all shards.
bool insert(const Key &key, const T &value)
Insert key with a copy of value, only if key is absent.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void print_rule()
Prints a horizontal rule for example output separation.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
Sharded concurrent hash map (Aleph::ConcurrentHashMap).