48#include <gtest/gtest.h>
56class Pair_Input_Iterator
58 const std::vector<std::pair<int, std::string>> *items_ =
nullptr;
63 using iterator_category = std::input_iterator_tag;
64 using value_type = std::pair<int, std::string>;
65 using difference_type = std::ptrdiff_t;
67 using reference =
const value_type &;
69 Pair_Input_Iterator() =
default;
71 Pair_Input_Iterator(
const std::vector<std::pair<int, std::string>> &items,
73 : items_(&items), pos_(pos) {}
77 Pair_Input_Iterator &operator++()
noexcept
83 Pair_Input_Iterator operator++(
int)
noexcept
85 Pair_Input_Iterator
ret = *
this;
90 bool operator==(
const Pair_Input_Iterator &it)
const noexcept
92 return items_ == it.items_
and pos_ == it.pos_;
95 bool operator!=(
const Pair_Input_Iterator &it)
const noexcept
97 return not (*
this == it);
148 {3,
"THREE"}, {2,
"two"}};
157 const std::vector<std::pair<int, std::string>> items =
158 {{3,
"three"}, {1,
"one"}, {2,
"two"}};
161 Pair_Input_Iterator(items, items.size()));
227 std::vector<std::string>
ks;
229 for (
auto [
k, v] :
m)
234 EXPECT_EQ(
ks, (std::vector<std::string>{
"a",
"b",
"c"}));
238 for (
auto [
k, v] :
m)
245 auto it =
m.
find(
"b");
279 auto [lo, hi] =
m.equal_range(20);
281 auto [
lo2,
hi2] =
m.equal_range(15);
290 auto vs =
m.values();
338 = {{1,
"one"}, {5,
"five"}, {3,
"three"}};
348 const int *
kp =
m.keys_data();
349 const int *
vp =
m.values_data();
350 for (
size_t i = 0; i <
m.
size(); ++i)
358 std::mt19937
rng(20260702);
359 std::uniform_int_distribution<int>
key_dist(0, 150);
360 std::uniform_int_distribution<int>
val_dist(0, 1000000);
361 std::uniform_int_distribution<int>
op_dist(0, 3);
364 std::map<int, int> ref;
366 for (
int step = 0; step < 4000; ++step)
377 EXPECT_EQ(
fm.insert(
k, v).second, ref.insert({k, v}).second);
384 const auto it = ref.find(
k);
396 for (
const auto &[
k, v] : ref)
Random-access proxy iterator over (key, value) entries.
Ordered map stored as two parallel sorted contiguous arrays.
iterator begin() noexcept
Iterator to the entry with the smallest key. O(1).
iterator end() noexcept
Iterator past the entry with the greatest key. O(1).
void swap(ODhashTable &other) noexcept
constexpr bool contains(const Key &key) const noexcept
Alias for has().
constexpr size_t size() const noexcept
Returns the number of entries in the table.
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.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
bool operator!=(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().
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
and
Check uniqueness with explicit hash + equality functors.
Matrix< Trow, Tcol, NumType > operator*(const NumType &scalar, const Matrix< Trow, Tcol, NumType > &m)
Scalar-matrix multiplication (scalar * matrix).
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Sorted-array map (Aleph::FlatMap), a cache-friendly ordered map.