38#include <gtest/gtest.h>
145 std::string key =
"test";
148 auto *
pair = map.insert(key, value);
157 std::string key =
"moved";
158 std::string value =
"hello_world";
160 auto *
pair = int_map.insert(100, std::move(value));
168 std::string key =
"key";
171 auto *
pair = map.insert(std::move(key), std::move(value));
179 std::string key =
"movekey";
182 auto *
pair = map.insert(std::move(key), value);
190 map.insert(
"dup", 1);
191 auto *
pair = map.insert(
"dup", 2);
212 auto *
pair = map.search(
"three");
222 auto *
pair = map.search(
"nonexistent");
230 std::string key =
"two";
231 auto *
pair = map.search(std::move(key));
238 auto *
pair = map.search(
"anything");
263 std::string key =
"three";
270 EXPECT_EQ(map.contains(
"one"), map.has(
"one"));
271 EXPECT_EQ(map.contains(
"nonexistent"), map.has(
"nonexistent"));
277 std::string key =
"two";
289 int & value = map.find(
"three");
297 map.find(
"two") = 22;
304 EXPECT_THROW((
void)map.find(
"nonexistent"), std::domain_error);
310 std::string key =
"four";
319 const int & value =
const_map.find(
"one");
344 map[
"new_key"] = 100;
351 int & value = map[
"defaulted"];
359 std::string key =
"moved_key";
360 map[std::move(key)] = 55;
398 EXPECT_THROW(map.remove(
"nonexistent"), std::domain_error);
404 std::string key =
"two";
406 map.remove(std::move(key));
427 auto *
pair = map.search(
"three");
430 map.remove_by_data(
pair->second);
451 else if (
k ==
"two")
has_two =
true;
532 auto *
pair = map.search(
"one");
542 auto *
pair = map.search(
"two");
553 auto *
pair = map.search(
"three");
567 auto *
pair = map.search(
"four");
629 auto &
pair = it.get_curr();
648 map.traverse([&
sum](
const auto &
pair) {
661 bool result = map.traverse([&
count](
const auto &) {
686 map.insert(
"test", 42);
687 auto *
pair = map.search(
"test");
710 constexpr int N = 10000;
711 for (
int i = 0; i <
N; ++i)
714 EXPECT_EQ(map.size(),
static_cast<size_t>(
N));
717 for (
int i = 0; i <
N; ++i)
728 constexpr int N = 1000;
729 for (
int i = 0; i <
N; ++i)
733 for (
int i = 0; i <
N; i += 2)
736 EXPECT_EQ(map.size(),
static_cast<size_t>(
N / 2));
739 for (
int i = 0; i <
N; ++i)
752 for (
int i = 0; i < 500; ++i)
762 for (
int i = 400; i < 500; ++i)
779 map.insert(
"neg", -100);
856 static_assert(std::is_same_v<MapODhash<std::string, int>::Key_Type, std::string>);
857 static_assert(std::is_same_v<MapODhash<std::string, int>::Data_Type,
int>);
858 static_assert(std::is_same_v<MapODhash<std::string, int>::Value_Type,
int>);
859 static_assert(std::is_same_v<MapODhash<std::string, int>::Item_Type,
860 std::pair<std::string, int>>);
873 for (
int i = 0; i < 100; ++i)
875 std::string val = std::to_string(i * 10);
883 for (
int i = 0; i < 100; ++i)
900 return pair.second > 2;
911 return pair.second * 2;
939 return pair.second > 0;
947 return pair.second > 0;
958 return pair.second == 3;
964 return pair.second == 10;
976 ::testing::InitGoogleTest(&
argc,
argv);
T & insert(const T &item)
Insert a new item by copy.
size_t size() const noexcept
Count the number of elements of the list.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criteria.
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criteria.
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
MapODhash< std::string, int > map
MapODhash< int, std::string > int_map
MapOLhash< std::string, int > map
TEST_F(MapODhashTest, DefaultConstruction)
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Open addressing hash map using double hashing.
Open addressing hash map using linear probing.
void remove(const Key &key)
Remove an entry by key.
bool has(const Key &key) const noexcept
Check if a key exists in the map.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair (copy semantics).
Aleph::DynList< T > keys() const
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Dynamic map with open hashing.