35#include <gtest/gtest.h>
51 struct DirectionalIntCompare
55 bool operator () (
const int lhs,
const int rhs)
const noexcept
57 return reverse ? lhs > rhs : lhs < rhs;
61 template <
class ArrayType>
64 std::vector<typename ArrayType::Item_Type>
out;
65 out.reserve(array.size());
66 for (
size_t i = 0; i < array.size(); ++i)
67 out.push_back(array[i]);
75 auto one = empty.
insert(10);
105 auto duplicate = one.
insert(7);
118 for (
int x : {4, 1, 7, 3, 9, 2})
128 for (
int i = 0; i < 10; ++i)
131 auto [left, right] = set.
split(5);
135 auto joined = left.join(right);
136 EXPECT_EQ(
to_vector(
joined.keys()), (std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
147 EXPECT_THROW((
void)left.join(right), std::domain_error);
160 EXPECT_THROW((
void)left.join(right), std::domain_error);
165 std::mt19937
rng(0x5EEDu);
166 std::uniform_int_distribution<int>
key_dist(0, 80);
167 std::uniform_int_distribution<int>
op_dist(0, 1);
170 std::set<int> reference;
186 reference.insert(key);
191 reference.erase(key);
197 std::vector<int>(reference.begin(), reference.end()));
208 auto one = empty.
insert(1, std::string(
"one"));
209 auto two = one.
insert(2, std::string(
"two"));
236 .insert(4, std::string(
"four"))
237 .insert(4, std::string(
"cuatro"));
248 for (
int i = 0; i < 6; ++i)
249 map = map.
insert(i, std::to_string(i));
251 auto [left, right] = map.
split(3);
256 auto items =
joined.items();
258 for (
size_t i = 0; i < items.size(); ++i)
260 EXPECT_EQ(items[i].first,
static_cast<int>(i));
261 EXPECT_EQ(items[i].second, std::to_string(i));
269 left = left.
insert(1, std::string(
"one")).
insert(2, std::string(
"two"));
272 right = right.
insert(6, std::string(
"six"))
273 .
insert(5, std::string(
"five"))
274 .
insert(4, std::string(
"four"));
278 EXPECT_THROW((
void)left.join(right), std::domain_error);
284 auto one = map.
insert(1, std::make_unique<int>(10));
301 std::mt19937
rng(0xBADC0DEu);
302 std::uniform_int_distribution<int>
key_dist(0, 60);
303 std::uniform_int_distribution<int>
value_dist(-1000, 1000);
304 std::uniform_int_distribution<int>
op_dist(0, 2);
307 std::map<int, int> reference;
325 reference.insert({key,
value});
331 reference[key] =
value;
336 reference.erase(key);
341 for (
const auto &[
k, v] : reference)
size_t size_t int32_t value
size_t size_t int32_t * out
Immutable ordered map backed by a path-copying treap.
std::pair< PersistentTreapMap, PersistentTreapMap > split(const Key &pivot) const
Split this version around pivot.
and std::constructible_from< T, VArg && > PersistentTreapMap insert_or_assign(KArg &&key, VArg &&value) const
Return a new version with key assigned to value.
PersistentTreapMap erase(const Key &key) const
Return a new version without key.
static PersistentTreapMap join(const PersistentTreapMap &left, const PersistentTreapMap &right)
Join two ordered, non-overlapping map versions.
bool verify() const
Verify treap, BST and cached-size invariants.
and std::constructible_from< T, VArg && > PersistentTreapMap insert(KArg &&key, VArg &&value) const
Return a new version with a binding inserted if absent.
Immutable ordered set backed by a path-copying treap.
Array< Key > keys() const
Return all keys in sorted order.
bool verify() const
Verify treap, BST and cached-size invariants.
PersistentTreapSet erase(const Key &key) const
Return a new version without key.
PersistentTreapSet insert(const Key &key) const
Return a new version with key inserted by copy.
std::pair< PersistentTreapSet, PersistentTreapSet > split(const Key &pivot) const
Split this version around pivot.
bool is_empty() const noexcept
Return true when the set has no keys.
bool contains(const Key &key) const
Test whether key is present.
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 reverse(Itor beg, Itor end)
Reverse elements in a range.
size_t size(Node *root) noexcept
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.
Immutable path-copying treap set and map.