12
12
13
13
namespace yakushima {
14
14
15
- template <class ValueType , bool NeedSize>
15
+ template <class ValueType , bool NeedSize, bool NeedKey >
16
16
using scan_result_elem = typename std::conditional_t <
17
- NeedSize,
18
- std::tuple<std::string, ValueType*, std::size_t >,
19
- std::tuple<std::string, ValueType*>>;
17
+ NeedKey,
18
+ std::conditional_t <
19
+ NeedSize,
20
+ std::tuple<std::string, ValueType*, std::size_t >,
21
+ std::tuple<std::string, ValueType*>>,
22
+ std::conditional_t <
23
+ NeedSize,
24
+ std::tuple<ValueType*, std::size_t >,
25
+ ValueType*>
26
+ >;
20
27
21
- template <class ValueType , bool NeedSize>
22
- using scan_result_t = std::vector<scan_result_elem<ValueType, NeedSize>>;
28
+ template <class ValueType , bool NeedSize, bool NeedKey >
29
+ using scan_result_t = std::vector<scan_result_elem<ValueType, NeedSize, NeedKey >>;
23
30
24
31
// forward declaration
25
- template <class ValueType , bool NeedSize>
32
+ template <class ValueType , bool NeedSize, bool NeedKey >
26
33
static status
27
34
scan_border (border_node** target, std::string_view l_key, scan_endpoint l_end,
28
35
std::string_view r_key, scan_endpoint r_end,
29
- scan_result_t <ValueType, NeedSize>& tuple_list,
36
+ scan_result_t <ValueType, NeedSize, NeedKey >& tuple_list,
30
37
node_version64_body& v_at_fb,
31
38
std::vector<std::tuple<std::string, node_version64_body,
32
39
node_version64*>>* node_version_vec,
@@ -56,12 +63,12 @@ inline status scan_check_retry(border_node* const bn,
56
63
/* *
57
64
* scan for some try nodes which is not root.
58
65
*/
59
- template <class ValueType , bool NeedSize = true >
66
+ template <class ValueType , bool NeedSize = true , bool NeedKey >
60
67
static status
61
- scan (base_node* const root, const std::string_view l_key,
68
+ scan_node (base_node* const root, const std::string_view l_key,
62
69
const scan_endpoint l_end, const std::string_view r_key,
63
70
const scan_endpoint r_end,
64
- scan_result_t <ValueType, NeedSize>& tuple_list,
71
+ scan_result_t <ValueType, NeedSize, NeedKey >& tuple_list,
65
72
std::vector<std::pair<node_version64_body, node_version64*>>* const
66
73
node_version_vec,
67
74
const std::string& key_prefix, const std::size_t max_size) {
@@ -130,7 +137,7 @@ scan(base_node* const root, const std::string_view l_key,
130
137
}
131
138
132
139
// scan the border node
133
- check_status = scan_border<ValueType, NeedSize>(
140
+ check_status = scan_border<ValueType, NeedSize, NeedKey >(
134
141
&bn, l_key, l_end, r_key, r_end, tuple_list, check_v,
135
142
node_version_vec, key_prefix, max_size);
136
143
@@ -168,12 +175,12 @@ scan(base_node* const root, const std::string_view l_key,
168
175
/* *
169
176
* scan for some leafnode of b+tree.
170
177
*/
171
- template <class ValueType , bool NeedSize = true >
178
+ template <class ValueType , bool NeedSize, bool NeedKey >
172
179
static status
173
180
scan_border (border_node** const target, const std::string_view l_key,
174
181
const scan_endpoint l_end, const std::string_view r_key,
175
182
const scan_endpoint r_end,
176
- scan_result_t <ValueType, NeedSize>& tuple_list,
183
+ scan_result_t <ValueType, NeedSize, NeedKey >& tuple_list,
177
184
node_version64_body& v_at_fb,
178
185
std::vector<std::pair<node_version64_body, node_version64*>>* const
179
186
node_version_vec,
@@ -319,7 +326,7 @@ scan_border(border_node** const target, const std::string_view l_key,
319
326
arg_r_end = scan_endpoint::INF;
320
327
}
321
328
}
322
- check_status = scan <ValueType, NeedSize>(
329
+ check_status = scan_node <ValueType, NeedSize, NeedKey >(
323
330
next_layer, arg_l_key, arg_l_end, arg_r_key, arg_r_end,
324
331
tuple_list, node_version_vec, full_key, max_size);
325
332
if (check_status != status::OK) {
@@ -331,13 +338,20 @@ scan_border(border_node** const target, const std::string_view l_key,
331
338
auto in_range = [&full_key, &tuple_list, &vp, &node_version_vec,
332
339
&v_at_fb, &node_version_ptr, &tuple_pushed_num,
333
340
max_size]() {
334
- if constexpr (NeedSize) {
341
+ if constexpr (NeedSize && NeedKey ) {
335
342
tuple_list.emplace_back (std::make_tuple (
336
343
full_key, static_cast <ValueType*>(value::get_body (vp)),
337
344
value::get_len (vp)));
338
- } else {
345
+ } else if constexpr (NeedKey) {
339
346
tuple_list.emplace_back (std::make_tuple (
340
347
full_key, static_cast <ValueType*>(value::get_body (vp))));
348
+ } else if constexpr (NeedSize) {
349
+ tuple_list.emplace_back (std::make_tuple (
350
+ static_cast <ValueType*>(value::get_body (vp)),
351
+ value::get_len (vp)));
352
+ } else {
353
+ tuple_list.emplace_back (
354
+ static_cast <ValueType*>(value::get_body (vp)));
341
355
}
342
356
if (node_version_vec != nullptr ) {
343
357
/* *
0 commit comments