Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
transposition_table_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31#include <gtest/gtest.h>
32
33#include <State_Search.H>
34
35using namespace Aleph;
36
37namespace
38{
39
40struct DummyEntry
41{
42 size_t depth = 0;
43 int value = 0;
44};
45
46struct CollidingKey
47{
48 int value = 0;
49
50 [[nodiscard]] bool operator == (const CollidingKey &) const noexcept = default;
51};
52
53[[nodiscard]] inline size_t aleph_hash_value(const CollidingKey &) noexcept
54{
55 return 1u;
56}
57
58} // end namespace
59
61{
63 DummyEntry,
67
68 Table table;
69
70 EXPECT_TRUE(table.is_empty());
71 EXPECT_EQ(table.store(7, DummyEntry{1, 10}), TranspositionStoreStatus::Inserted);
72 EXPECT_FALSE(table.is_empty());
73 ASSERT_EQ(table.size(), 1u);
74
75 auto *entry = table.probe(7);
76 ASSERT_NE(entry, nullptr);
77 EXPECT_EQ(entry->depth, 1u);
78 EXPECT_EQ(entry->value, 10);
79
80 EXPECT_EQ(table.store(7, DummyEntry{0, 5}), TranspositionStoreStatus::Rejected);
81 entry = table.probe(7);
82 ASSERT_NE(entry, nullptr);
83 EXPECT_EQ(entry->depth, 1u);
84 EXPECT_EQ(entry->value, 10);
85
86 EXPECT_EQ(table.store(7, DummyEntry{3, 15}), TranspositionStoreStatus::Replaced);
87 entry = table.probe(7);
88 ASSERT_NE(entry, nullptr);
89 EXPECT_EQ(entry->depth, 3u);
90 EXPECT_EQ(entry->value, 15);
91
92 EXPECT_EQ(table.probe(99), nullptr);
93
94 const auto &stats = table.stats();
95 EXPECT_EQ(stats.probes, 4u);
96 EXPECT_EQ(stats.hits, 3u);
97 EXPECT_EQ(stats.misses, 1u);
98 EXPECT_EQ(stats.stores, 2u);
99 EXPECT_EQ(stats.replacements, 1u);
100 EXPECT_EQ(stats.rejected_updates, 1u);
101}
102
104{
106
107 Table table;
108
109 EXPECT_EQ(table.store(CollidingKey{1}, DummyEntry{1, 11}),
110 TranspositionStoreStatus::Inserted);
111 EXPECT_EQ(table.store(CollidingKey{2}, DummyEntry{2, 22}),
112 TranspositionStoreStatus::Inserted);
113
114 auto *first = table.probe(CollidingKey{1});
115 auto *second = table.probe(CollidingKey{2});
116
117 ASSERT_NE(first, nullptr);
118 ASSERT_NE(second, nullptr);
119 EXPECT_EQ(first->depth, 1u);
120 EXPECT_EQ(first->value, 11);
121 EXPECT_EQ(second->depth, 2u);
122 EXPECT_EQ(second->value, 22);
123 EXPECT_EQ(table.size(), 2u);
124}
Umbrella header for the implicit state-space search framework.
Generic linear hash table.
const size_t & size() const noexcept
Returns the number of elements in the table.
bool is_empty() const noexcept
return true is table is empty
Transposition-table container built on top of Aleph hash maps.
Stats stats() const
Computes statistics about chain length distribution.
Definition hashDry.H:1047
#define TEST(name)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
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.
size_t aleph_hash_value(const AdversarialTranspositionKey< StateKey > &key) noexcept
Definition Negamax.H:134
Open addressing hash map using linear probing.
Replacement policy that prefers entries searched to greater depth.