return lookup_result_t<NODE_TYPE>::end();
}
}
- auto result = STAGE_T::lower_bound_normalized(node_stage, key, history);
+
+ auto result_raw = STAGE_T::lower_bound(node_stage, key, history);
+#ifndef NDEBUG
+ if (result_raw.is_end()) {
+ assert(result_raw.mstat == MSTAT_END);
+ } else {
+ full_key_t<KeyT::VIEW> index;
+ STAGE_T::get_key_view(node_stage, result_raw.position, index);
+ assert_mstat(key, index, result_raw.mstat);
+ }
+#endif
+
+ // calculate MSTAT_NE3
+ if constexpr (FIELD_TYPE == field_type_t::N0) {
+ // currently only internal node checks mstat
+ if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
+ if (result_raw.mstat == MSTAT_NE2) {
+ auto cmp = compare_to<KeyT::HOBJ>(
+ key, node_stage[result_raw.position.index].shard_pool);
+ assert(cmp != MatchKindCMP::PO);
+ if (cmp != MatchKindCMP::EQ) {
+ result_raw.mstat = MSTAT_NE3;
+ }
+ }
+ }
+ }
+
+ auto result = normalize(std::move(result_raw));
if (result.is_end()) {
assert(node_stage.is_level_tail());
assert(result.p_value == nullptr);
*/
void get_largest_value(search_position_t& pos, const onode_t*& p_value) const override {
if constexpr (NODE_TYPE == node_type_t::LEAF) {
- STAGE_T::lookup_largest_normalized(extent.read(), pos, p_value);
+ STAGE_T::lookup_largest(extent.read(), cast_down_fill_0<STAGE>(pos), p_value);
} else {
assert(false && "impossible path");
}
}
}
- /*
- * Lookup interfaces
- */
-
- static void lookup_largest_normalized(
- const container_t& container,
- search_position_t& position,
- const value_t*& p_value) {
- if constexpr (STAGE == STAGE_LEFT) {
- lookup_largest(container, position, p_value);
- return;
- }
- position.index = 0;
- auto& pos_nxt = position.nxt;
- if constexpr (STAGE == STAGE_STRING) {
- lookup_largest(container, pos_nxt, p_value);
- return;
- }
- pos_nxt.index = 0;
- auto& pos_nxt_nxt = pos_nxt.nxt;
- if constexpr (STAGE == STAGE_RIGHT) {
- lookup_largest(container, pos_nxt_nxt, p_value);
- return;
- }
- assert(false);
- }
-
- static lookup_result_t<NODE_TYPE> lower_bound_normalized(
- const container_t& container,
- const full_key_t<KeyT::HOBJ>& key,
- MatchHistory& history) {
- auto&& result = lower_bound(container, key, history);
-#ifndef NDEBUG
- if (result.is_end()) {
- assert(result.mstat == MSTAT_END);
- } else {
- full_key_t<KeyT::VIEW> index;
- get_key_view(container, result.position, index);
- assert_mstat(key, index, result.mstat);
- }
-#endif
- if constexpr (container_t::FIELD_TYPE == field_type_t::N0) {
- // currently only internal node checks mstat
- if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
- if (result.mstat == MSTAT_NE2) {
- auto cmp = compare_to<KeyT::HOBJ>(
- key, container[result.position.index].shard_pool);
- assert(cmp != MatchKindCMP::PO);
- if (cmp != MatchKindCMP::EQ) {
- result.mstat = MSTAT_NE3;
- }
- }
- }
- }
- return normalize(std::move(result));
- }
-
static std::ostream& dump(const container_t& container,
std::ostream& os,
const std::string& prefix,
using search_position_t = staged_position_t<STAGE_TOP>;
-template <match_stage_t STAGE, typename = std::enable_if_t<STAGE == STAGE_TOP>>
-const search_position_t& cast_down(const search_position_t& pos) { return pos; }
-
-template <match_stage_t STAGE, typename = std::enable_if_t<STAGE != STAGE_TOP>>
+template <match_stage_t STAGE>
const staged_position_t<STAGE>& cast_down(const search_position_t& pos) {
- if constexpr (STAGE == STAGE_STRING) {
+ if constexpr (STAGE == STAGE_LEFT) {
+ return pos;
+ } else if constexpr (STAGE == STAGE_STRING) {
#ifndef NDEBUG
if (pos.is_end()) {
assert(pos.nxt.is_end());
}
#endif
return pos.nxt;
- } else if (STAGE == STAGE_RIGHT) {
+ } else if constexpr (STAGE == STAGE_RIGHT) {
#ifndef NDEBUG
if (pos.is_end()) {
assert(pos.nxt.nxt.is_end());
#endif
return pos.nxt.nxt;
} else {
- assert(false);
+ assert(false && "impossible path");
}
}
return const_cast<staged_position_t<STAGE>&>(cast_down<STAGE>(_pos));
}
+template <match_stage_t STAGE>
+staged_position_t<STAGE>& cast_down_fill_0(search_position_t& pos) {
+ if constexpr (STAGE == STAGE_LEFT) {
+ return pos;
+ } if constexpr (STAGE == STAGE_STRING) {
+ pos.index = 0;
+ return pos.nxt;
+ } else if constexpr (STAGE == STAGE_RIGHT) {
+ pos.index = 0;
+ pos.nxt.index = 0;
+ return pos.nxt.nxt;
+ } else {
+ assert(false && "impossible path");
+ }
+}
+
inline search_position_t&& normalize(search_position_t&& pos) { return std::move(pos); }
template <match_stage_t STAGE, typename = std::enable_if_t<STAGE != STAGE_TOP>>