11
11
#include < unordered_map>
12
12
13
13
#include " hashtable.h"
14
+ #include " hashtables/batch_inserter.hpp"
14
15
#include " hashtables/cas_kht.hpp"
15
16
#include " hashtables/simple_kht.hpp"
16
17
#include " test_lib.hpp"
@@ -47,9 +48,11 @@ class HashtableTest : public ::testing::TestWithParam<const char*> {
47
48
return nullptr ;
48
49
}());
49
50
ASSERT_NE (ht_, nullptr ) << " Invalid hashtable type: " << ht_name;
51
+ inserter_ = HTBatchInserter<>(ht_.get ());
50
52
}
51
53
52
54
std::unique_ptr<kmercounter::BaseHashTable> ht_;
55
+ HTBatchInserter<> inserter_;
53
56
};
54
57
55
58
// / Correctness test for insertion and lookup without prefetch.
@@ -76,19 +79,17 @@ TEST_P(HashtableTest, NO_PREFETCH_TEST) {
76
79
77
80
TEST_P (HashtableTest, SIMPLE_BATCH_INSERT_TEST) {
78
81
// Insertion.
79
- std::array<InsertFindArgument, 2 > arguments{
80
- InsertFindArgument{key : 12 , value : 128 },
81
- InsertFindArgument{key : 23 , value : 256 }};
82
- InsertFindArguments keypairs (arguments);
83
- ht_->insert_batch (keypairs);
84
- ht_->flush_insert_queue ();
82
+ inserter_.insert (12 , 128 );
83
+ inserter_.insert (23 , 256 );
84
+ inserter_.flush ();
85
85
86
86
// Look up.
87
- arguments[0 ] = InsertFindArgument{key : 12 , id : 123 };
88
- arguments[1 ] = InsertFindArgument{key : 23 , id : 321 };
87
+ std::array<InsertFindArgument, 2 > arguments{
88
+ InsertFindArgument{key : 12 , id : 123 },
89
+ InsertFindArgument{key : 23 , id : 321 }};
89
90
std::array<FindResult, HT_TESTS_BATCH_LENGTH> results{};
90
91
ValuePairs valuepairs{0 , results.data ()};
91
- ht_->find_batch (keypairs , valuepairs);
92
+ ht_->find_batch (arguments , valuepairs);
92
93
ht_->flush_find_queue (valuepairs);
93
94
94
95
// Check for correctness.
@@ -101,24 +102,22 @@ TEST_P(HashtableTest, SIMPLE_BATCH_INSERT_TEST) {
101
102
102
103
TEST_P (HashtableTest, SIMPLE_BATCH_UPDATE_TEST) {
103
104
// Insertion.
104
- std::array<InsertFindArgument, 2 > arguments{
105
- InsertFindArgument{key : 12 , value : 128 , part_id : 0 },
106
- InsertFindArgument{key : 23 , value : 256 , part_id : 0 }};
107
- InsertFindArguments keypairs (arguments);
108
- ht_->insert_batch (InsertFindArguments (arguments));
105
+ inserter_.insert (12 , 128 );
106
+ inserter_.insert (23 , 256 );
107
+ inserter_.flush ();
109
108
110
109
// Update.
111
- arguments[0 ].value = 1025 ;
112
- arguments[1 ].value = 4097 ;
113
- ht_->insert_batch (keypairs);
114
- ht_->flush_insert_queue ();
110
+ inserter_.insert (12 , 1025 );
111
+ inserter_.insert (23 , 4097 );
112
+ inserter_.flush ();
115
113
116
114
// Look up.
117
- arguments[0 ].id = 123 ;
118
- arguments[1 ].id = 321 ;
115
+ std::array<InsertFindArgument, 2 > arguments{
116
+ InsertFindArgument{key : 12 , id : 123 },
117
+ InsertFindArgument{key : 23 , id : 321 }};
119
118
std::array<FindResult, HT_TESTS_BATCH_LENGTH> values{};
120
119
ValuePairs valuepairs{0 , values.data ()};
121
- ht_->find_batch (keypairs , valuepairs);
120
+ ht_->find_batch (arguments , valuepairs);
122
121
ht_->flush_find_queue (valuepairs);
123
122
124
123
// Check for correctness.
@@ -141,20 +140,10 @@ TEST_P(HashtableTest, BATCH_QUERY_TEST) {
141
140
const uint64_t key = i;
142
141
const uint64_t value = i * i;
143
142
const uint64_t id = 2 * i;
144
- arguments[k].key = key;
145
- arguments[k].value = value;
146
- arguments[k].part_id = 0 ;
143
+ inserter_.insert (key, value);
147
144
reference_map[value] = id;
148
- if (++k == HT_TESTS_BATCH_LENGTH) {
149
- ht_->insert_batch (InsertFindArguments (arguments));
150
- k = 0 ;
151
- }
152
- }
153
- if (k != 0 ) {
154
- ht_->insert_batch (InsertFindArguments (arguments, k));
155
- k = 0 ;
156
145
}
157
- ht_-> flush_insert_queue ();
146
+ inserter_. flush ();
158
147
159
148
// Helper function for checking the result of the batch finds.
160
149
auto check_valuepairs = [&reference_map](const ValuePairs& vp) {
@@ -175,7 +164,6 @@ TEST_P(HashtableTest, BATCH_QUERY_TEST) {
175
164
for (uint64_t i = 0 ; i < test_size; i++) {
176
165
arguments[k].key = i;
177
166
arguments[k].id = 2 * i;
178
- arguments[k].part_id = 0 ;
179
167
if (++k == HT_TESTS_BATCH_LENGTH) {
180
168
ValuePairs valuepairs{0 , values};
181
169
ht_->find_batch (InsertFindArguments (arguments), valuepairs);
0 commit comments