37# include <gtest/gtest.h>
50using namespace testing;
55constexpr size_t N = 1000;
57template <
class HashTbl>
70template <
class HashTbl>
85 auto it =
tbl.get_it();
97 auto it =
tbl.get_it();
102 for (; it.has_curr(); it.next_ne())
105 auto ll =
l.
maps<
size_t>([](
auto &p)
106 {
return p.first; });
111 for (; it.has_curr(); it.prev_ne())
113 ll =
l.
maps<
size_t>([](
auto &p)
114 {
return p.first; });
151 auto stats =
tbl.stats();
152 EXPECT_EQ(stats.num_busy,
static_cast<size_t>(2));
161 auto *bucket =
decltype(
tbl)::key_to_bucket(ptr);
179 auto *p1 =
tbl.insert(10);
181 auto *p2 =
tbl.insert(10);
190 auto *p =
tbl.insert(5);
202 for (
int i = 0; i < 5; ++i)
210 auto constant_hash = [] (
const int &)
noexcept ->
size_t {
return 0u; };
214 auto *p1 =
tbl.insert(1);
215 auto *p2 =
tbl.insert(2);
216 auto *p3 =
tbl.insert(3);
223 auto stats =
tbl.stats();
224 EXPECT_EQ(stats.num_busy,
static_cast<size_t>(2));
225 EXPECT_EQ(stats.num_deleted,
static_cast<size_t>(1));
226 EXPECT_EQ(stats.num_busy + stats.num_deleted + stats.num_empty,
227 static_cast<size_t>(
tbl.capacity()));
228 EXPECT_GE(stats.max_len,
static_cast<size_t>(1));
239 for (
int i = 0; i < 10; ++i)
242 for (
int i = 0; i < 10; ++i)
249 auto const_hash = [](
int) {
return static_cast<size_t>(0); };
252 for (
int i = 0; i < 5; ++i)
255 for (
int i = 0; i < 5; ++i)
258 auto stats =
tbl.stats();
259 EXPECT_EQ(stats.num_busy,
static_cast<size_t>(5));
260 EXPECT_GE(stats.max_len,
static_cast<size_t>(5));
271 for (
int i = 0; i < 6; ++i)
279 for (
int i = 10; i < 16; ++i)
283 for (
int i : {0, 2, 4, 5, 10, 11, 12, 13, 14, 15})
290 auto *p1 =
tbl.search_or_insert(1);
292 auto *p2 =
tbl.search_or_insert(1);
351 auto const_hash = [](
int) {
return static_cast<size_t>(0); };
354 for (
int i = 0; i < 5; ++i)
393 const auto cap0 =
tbl.capacity();
394 for (
int i = 0; i < 10; ++i)
397 for (
int i = 0; i < 10; ++i)
425 for (
int i = 0; i < 5; ++i)
435 auto *p1 =
tbl.insert(10);
437 auto *p2 =
tbl.insert(10);
440 auto *p3 =
tbl.search_or_insert(10);
485 auto stats =
tbl.stats();
486 EXPECT_EQ(stats.num_busy,
static_cast<size_t>(2));
487 EXPECT_GE(stats.num_deleted,
static_cast<size_t>(0));
493 auto h2 = [](
int k) {
return static_cast<size_t>(
k * 13); };
502 for (
int i = 0; i < 5; ++i)
504 auto stats =
tbl.stats();
512 auto const_h2 = +[](
int) {
return static_cast<size_t>(0); };
518 auto stats =
tbl.stats();
519 EXPECT_EQ(stats.num_busy,
static_cast<size_t>(3));
520 EXPECT_GE(stats.max_len,
static_cast<size_t>(1));
532 const auto cap0 =
tbl.capacity();
533 for (
int i = 0; i < 10; ++i)
536 for (
int i = 0; i < 10; ++i)
552 std::set<int> inserted;
553 for (
int i = 0; i < 7; ++i)
556 inserted.insert(i * 2);
558 auto it =
tbl.get_it();
560 for (; it.has_curr(); it.next_ne())
571 auto const_hash = +[](
const int &) {
return static_cast<size_t>(0); };
594 0.9f, 10.0f,
true,
true);
597 auto * b1 =
new Bucket(1);
598 auto * b2 =
new Bucket(2);
613 delete tbl.remove(b2);
614 delete tbl.remove(
b3);
619 auto const_hash = +[](
const int &) {
return static_cast<size_t>(1); };
624 for (
int k : {1, 2, 3})
642 auto * b1 =
new Bucket(42);
645 auto * b2 =
new Bucket(42);
646 auto * found =
tbl.search_or_insert(b2);
650 delete tbl.remove(b1);
657 auto * b1 =
new Bucket(1);
658 auto * b2 =
new Bucket(2);
668 delete dst.remove(b1);
669 delete dst.remove(b2);
677 auto * b1 =
new Bucket(7);
681 auto * b2 =
new Bucket(7);
685 auto * found =
tbl.search(7);
688 delete tbl.remove(b1);
693 auto const_hash = +[](
const int &) {
return static_cast<size_t>(3); };
698 auto * b1 =
new Bucket(1);
699 auto * b2 =
new Bucket(2);
705 auto * first =
tbl.search(1);
709 delete tbl.remove(b1);
710 delete tbl.remove(b2);
711 delete tbl.remove(
b3);
745 for (
int k : {1, 2, 3})
758 auto const_hash = +[](
const int &) {
return static_cast<size_t>(0); };
776 auto * b1 =
new Bucket(1);
777 auto * b2 =
new Bucket(2);
807 for (
int k : {1, 2, 102})
811 tbl.set_hash_fct(+[](
const int &
k) {
return static_cast<size_t>(
k * 2); });
820 delete tbl.remove(
tbl.search(1));
821 delete tbl.remove(
tbl.search(2));
822 delete tbl.remove(
tbl.search(102));
831 const auto cap =
tbl.capacity();
832 for (
int k = 0;
k < 50; ++
k)
845 bool operator()(
int a,
int b)
const {
return (a % 10) == (b % 10); }
848 auto const_hash = +[](
const int &) {
return static_cast<size_t>(0); };
853 auto * b1 =
new Bucket(10);
854 auto * b2 =
new Bucket(20);
859 delete tbl.remove(b1);
874static_assert(!std::is_copy_constructible_v<LhashTable<int>>,
875 "LhashTable should not be copy constructible");
876static_assert(!std::is_copy_assignable_v<LhashTable<int>>,
877 "LhashTable should not be copy assignable");
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
void insert(Dlink *node) noexcept
Insert node after this.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
void empty() noexcept
empty the list
Bucket * remove(Bucket *bucket) noexcept
Removes bucket from the table.
Bucket * insert(Bucket *bucket)
Inserts bucket into the table and returns its address if the key is not already in the table; otherwi...
const size_t & size() const noexcept
Returns the number of elements contained in the table.
const size_t & capacity() const noexcept
Returns the table capacity.
void swap(GenLhashTable &other) noexcept
Bucket * search(const Key &key) const noexcept
Search in the table for a bucket with key.
constexpr bool is_empty() const noexcept
Open addressing hash table with double hashing collision resolution.
void set_second_hash_fct(Hash_Fct fct) noexcept
Key * search(const Key &key) const noexcept
searches the table for the key.
void swap(ODhashTable &other) noexcept
Open addressing hash table with linear probing collision resolution.
Key * search(const Key &key) const noexcept
Finds the key and returns the associated record if key is find inside the table; otherwise,...
void swap(OLhashTable &other) noexcept
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
constexpr size_t size() const noexcept
Returns the number of entries in the table.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Types< MapODhash< size_t, string >, MapOLhash< size_t, string >, DynMapLinHash< size_t, string >, DynMapHash< size_t, string > > HashTypes
REGISTER_TYPED_TEST_CASE_P(EmptyOHashTest, With_exception)
TYPED_TEST_P(EmptyOHashTest, With_exception)
INSTANTIATE_TYPED_TEST_CASE_P(Empty, EmptyOHashTest, HashTypes)
TYPED_TEST_CASE_P(OHashTest)
MapOLhash< int, Foo > tbl
Main namespace for Aleph-w library functions.
const float hash_default_upper_alpha
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Container< T > range(const T start, const T end, const T step=1)
Generate a range of values [start, end] with a given step.
const float hash_default_lower_alpha
Generic hash table with collision resolution by separate chaining and buckets without virtual destruc...
Open addressing hash map using linear probing.
Dynamic map with open hashing.
Dynamic set implementations based on hash tables.
Linear hashing with dynamic bucket expansion.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.