node_future<Ref<tree_cursor_t>>
InternalNode::get_next_cursor(context_t c, const search_position_t& pos)
{
- assert(!impl->is_empty());
+ impl->validate_non_empty();
if (pos.is_end()) {
assert(impl->is_level_tail());
return get_next_cursor_from_parent(c);
).safe_then([c, old_root_addr,
super = std::move(super)](auto fresh_node) mutable {
auto root = fresh_node.node;
- assert(root->impl->is_empty());
+ assert(root->impl->is_keys_empty());
auto p_value = root->impl->get_tail_value();
fresh_node.mut.copy_in_absolute(
const_cast<laddr_packed_t*>(p_value), old_root_addr);
node_future<Ref<tree_cursor_t>>
InternalNode::lookup_smallest(context_t c)
{
- assert(!impl->is_empty());
+ impl->validate_non_empty();
auto position = search_position_t::begin();
const laddr_packed_t* p_child_addr;
impl->get_slot(position, nullptr, &p_child_addr);
{
// NOTE: unlike LeafNode::lookup_largest(), this only works for the tail
// internal node to return the tail child address.
- assert(!impl->is_empty());
+ impl->validate_non_empty();
assert(impl->is_level_tail());
auto p_child_addr = impl->get_tail_value();
return get_or_track_child(c, search_position_t::end(), p_child_addr->value
node_future<> InternalNode::do_get_tree_stats(
context_t c, tree_stats_t& stats)
{
- assert(!impl->is_empty());
+ impl->validate_non_empty();
auto nstats = impl->get_stats();
stats.size_persistent_internal += nstats.size_persistent;
stats.size_filled_internal += nstats.size_filled;
node_future<Ref<tree_cursor_t>>
LeafNode::get_next_cursor(context_t c, const search_position_t& pos)
{
- assert(!impl->is_empty());
+ impl->validate_non_empty();
search_position_t next_pos = pos;
key_view_t index_key;
const value_header_t* p_value_header = nullptr;
node_future<Ref<tree_cursor_t>>
LeafNode::lookup_smallest(context_t)
{
- if (unlikely(impl->is_empty())) {
+ if (unlikely(impl->is_keys_empty())) {
assert(is_root());
return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
tree_cursor_t::create_end(this));
node_future<Ref<tree_cursor_t>>
LeafNode::lookup_largest(context_t)
{
- if (unlikely(impl->is_empty())) {
+ if (unlikely(impl->is_keys_empty())) {
assert(is_root());
return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
tree_cursor_t::create_end(this));
nextent_state_t get_extent_state() const override { return extent.get_state(); }
void prepare_mutate(context_t c) override { return extent.prepare_mutate(c); }
bool is_level_tail() const override { return extent.read().is_level_tail(); }
- bool is_empty() const override { return extent.read().keys() == 0; }
+
+ void validate_non_empty() const override {
+ if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
+ if (is_level_tail()) {
+ return;
+ }
+ }
+ assert(!is_keys_empty());
+ }
+ bool is_keys_empty() const override { return extent.read().keys() == 0; }
+
level_t level() const override { return extent.read().level(); }
node_offset_t free_size() const override { return extent.read().free_size(); }
std::optional<key_view_t> get_pivot_index() const override {
- assert(!is_empty());
if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
if (is_level_tail()) {
return std::nullopt;
}
}
+ assert(!is_keys_empty());
key_view_t pivot_index;
get_largest_slot(nullptr, &pivot_index, nullptr);
return {pivot_index};
node_stats_t stats;
auto& node_stage = extent.read();
key_view_t index_key;
- if (node_stage.keys()) {
+ if (!is_keys_empty()) {
STAGE_T::get_stats(node_stage, stats, index_key);
}
stats.size_persistent = node_stage_t::EXTENT_SIZE;
<< "B, value=" << stats.size_value << "B";
os << ":\n header: " << node_stage_t::header_size() << "B";
size_t size = 0u;
- if (node_stage.keys()) {
+ if (!is_keys_empty()) {
STAGE_T::dump(node_stage, os, " ", size, p_start);
} else {
size += node_stage_t::header_size();
void get_slot(const search_position_t& pos,
key_view_t* p_index_key = nullptr,
const value_t** pp_value = nullptr) const override {
- assert(!is_empty());
+ assert(!is_keys_empty());
assert(!pos.is_end());
if (p_index_key && pp_value) {
STAGE_T::template get_slot<true, true>(
void get_next_slot(search_position_t& pos,
key_view_t* p_index_key = nullptr,
const value_t** pp_value = nullptr) const override {
- assert(!is_empty());
+ assert(!is_keys_empty());
assert(!pos.is_end());
bool find_next;
if (p_index_key && pp_value) {
void get_largest_slot(search_position_t* p_pos = nullptr,
key_view_t* p_index_key = nullptr,
const value_t** pp_value = nullptr) const override {
- assert(!is_empty());
- if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
- assert(!is_level_tail());
- }
+ assert(!is_keys_empty());
if (p_pos && p_index_key && pp_value) {
STAGE_T::template get_largest_slot<true, true, true>(
extent.read(), &cast_down_fill_0<STAGE>(*p_pos), p_index_key, pp_value);
key_view_t* index_key=nullptr, marker_t={}) const override {
auto& node_stage = extent.read();
if constexpr (NODE_TYPE == node_type_t::LEAF) {
- if (unlikely(node_stage.keys() == 0)) {
+ if (unlikely(is_keys_empty())) {
history.set<STAGE_LEFT>(MatchKindCMP::LT);
return lookup_result_t<NODE_TYPE>::end();
}
}
+ assert(!is_keys_empty());
typename STAGE_T::result_t result_raw;
if (index_key) {
auto& node_stage = extent.read();
match_stage_t insert_stage;
node_offset_t insert_size;
- if (unlikely(!node_stage.keys())) {
+ if (unlikely(is_keys_empty())) {
assert(insert_pos.is_end());
+ assert(is_level_tail());
insert_stage = STAGE;
insert_size = STAGE_T::template insert_size<KeyT::VIEW>(key, value);
} else {
const MatchHistory& history, match_stat_t mstat,
search_position_t& insert_pos) const override {
if constexpr (NODE_TYPE == node_type_t::LEAF) {
- if (unlikely(is_empty())) {
+ if (unlikely(is_keys_empty())) {
assert(insert_pos.is_end());
+ assert(is_level_tail());
return {STAGE, STAGE_T::template insert_size<KeyT::HOBJ>(key, value)};
} else {
return STAGE_T::evaluate_insert(