38#include <gtest/gtest.h>
60 for (
const auto & item : a)
62 std::sort(
out.begin(),
out.end());
67std::vector<T>
to_vector(
const std::set<T> & s)
69 return std::vector<T>(s.begin(), s.end());
72template <
typename K,
typename V>
73std::vector<K>
keys_of(
const std::map<K, V> &
m)
77 for (
const auto &
kv :
m)
78 out.push_back(
kv.first);
84 std::vector<std::string>
out;
89std::vector<std::string>
sorted(std::vector<std::string> v)
91 std::sort(v.begin(), v.end());
102 out.push_back(((key >> shift) & std::uint16_t{1}) ?
'1' :
'0');
109 std::vector<std::string>
out;
111 for (
const auto key :
keys)
113 std::sort(
out.begin(),
out.end());
119 std::vector<std::string>
out;
121 for (
const auto key :
keys)
123 std::sort(
out.begin(),
out.end());
128 const std::string &
prefix)
130 std::vector<std::string>
out;
131 for (
const auto key :
keys)
137 std::sort(
out.begin(),
out.end());
142static_assert(std::is_move_constructible_v<PatriciaSet<unsigned>>);
143static_assert(std::is_copy_constructible_v<PatriciaSet<unsigned>>);
144static_assert(std::is_move_constructible_v<PatriciaMap<unsigned, int>>);
145static_assert(std::is_copy_constructible_v<PatriciaMap<unsigned, int>>);
146static_assert(std::is_move_constructible_v<
148static_assert(
not std::is_copy_constructible_v<
185 const unsigned max = std::numeric_limits<unsigned>::max();
203 for (
unsigned key : {9U, 1U, 17U, 3U, 0
U})
344 s = std::move(
alias);
354 std::set<std::uint32_t> reference;
355 std::mt19937
rng(0x5eed1234U);
356 std::uniform_int_distribution<std::uint32_t>
key_dist(0, 4095);
357 std::uniform_int_distribution<int>
op_dist(0, 2);
359 for (
int step = 0; step < 20000; ++step)
382 std::set<std::uint16_t> reference;
384 std::mt19937
rng(0xC017B175U);
385 std::uniform_int_distribution<unsigned>
key_dist(
386 0, std::numeric_limits<std::uint16_t>::max());
390 const auto key =
static_cast<std::uint16_t
>(
key_dist(
rng));
395 <<
"Patricia disagreement inserting " << key;
397 <<
"RadixTree disagreement inserting " <<
encoded;
399 <<
"Prefix_Tree disagreement inserting " <<
encoded;
410 const auto key =
static_cast<std::uint16_t
>(
key_dist(
rng));
412 const bool expected = reference.contains(key);
414 <<
"Patricia contains disagreement for " << key;
416 <<
"RadixTree contains disagreement for " <<
encoded;
418 <<
"Prefix_Tree contains disagreement for " <<
encoded;
432 const auto key =
static_cast<std::uint16_t
>(
key_dist(
rng));
438 <<
"RadixTree prefix disagreement for " <<
prefix;
440 <<
"Prefix_Tree prefix disagreement for " <<
prefix;
447 <<
"Patricia scan prefix disagreement for " <<
prefix;
490 auto duplicate = std::make_unique<int>(2);
503 m.insert_or_assign(10,
"ten");
507 m.insert_or_assign(10,
"diez");
511 m.insert_or_assign(11,
"once");
671 std::map<std::uint32_t, int> reference;
672 std::mt19937
rng(0x0BADC0DEU);
673 std::uniform_int_distribution<std::uint32_t>
key_dist(0, 4095);
674 std::uniform_int_distribution<int>
value_dist(-10000, 10000);
675 std::uniform_int_distribution<int>
op_dist(0, 3);
677 for (
int step = 0; step < 10000; ++step)
685 reference.emplace(key,
value).second);
689 reference[key] =
value;
698 <<
"find presence disagreement at step " << step;
701 <<
"find value disagreement at step " << step;
709 for (
const auto &
kv : reference)
721 std::map<std::uint16_t, int> reference;
723 std::mt19937
rng(0xFACEB00CU);
724 std::uniform_int_distribution<unsigned>
key_dist(
725 0, std::numeric_limits<std::uint16_t>::max());
726 std::uniform_int_distribution<int>
value_dist(-5000, 5000);
730 const auto key =
static_cast<std::uint16_t
>(
key_dist(
rng));
738 <<
"PatriciaMap disagreement inserting " << key;
740 <<
"RadixTree disagreement inserting " <<
encoded;
742 <<
"Prefix_Tree disagreement inserting " <<
encoded;
747 reference[key] =
value;
752 <<
"Prefix_Tree missed new key " <<
encoded;
755 <<
"Prefix_Tree lost existing key " <<
encoded;
766 for (
const auto &
kv : reference)
785 const auto key =
static_cast<std::uint16_t
>(
key_dist(
rng));
789 for (
const auto &
kv : reference)
795 <<
"RadixTree prefix disagreement for " <<
prefix;
797 <<
"Prefix_Tree prefix disagreement for " <<
prefix;
size_t size_t int32_t value
size_t size_t int32_t * out
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
constexpr bool is_empty() const noexcept
Checks if the container is empty.
constexpr bool contains(const Key &key) const noexcept
Alias for has().
Compressed bitwise map for unsigned integral keys.
bool check_invariants() const noexcept
Verify structural invariants recursively.
bool insert(const Key key, const Value &value)
Insert key with a copy of value, only if key is absent.
void insert_or_assign(const Key key, Value value)
Insert key or overwrite the mapped value if key exists.
const Value * find(const Key key) const noexcept
Look up key.
bool contains(const Key key) const noexcept
Check whether key is stored.
bool is_empty() const noexcept
Check whether the map has no key-value pairs.
Compressed bitwise set for unsigned integral keys.
bool check_invariants() const noexcept
Verify structural invariants recursively.
size_t size() const noexcept
Return the number of stored keys.
bool insert(const Key key)
Insert key if absent.
bool erase(const Key key) noexcept
Remove key if present.
void clear() noexcept
Remove every key from the set.
bool is_empty() const noexcept
Check whether the set has no keys.
bool contains(const Key key) const noexcept
Check whether key is stored.
Array< Key > keys() const
Return all stored keys.
Owning prefix tree wrapper.
Compressed prefix tree mapping std::basic_string<Char> keys to values of type T.
Minimal std::expected-style result type for C++20.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
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.
DynList< Key > keys() const
Returns a list containing all keys in the table.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Key & find(const Key &key)
Finds a key and returns a reference to it.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
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.
static void prefix(Node *root, DynList< Node * > &acc)
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.
Trie (prefix tree) implementation.
static std::vector< std::string > to_sorted_vector(const DynArray< std::string > &words)
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
PATRICIA/crit-bit set and map for fixed-width unsigned integer keys.
Compressed prefix tree (Aleph::RadixTree) mapping string keys to values.