auto [liter, riter] = donor_is_left ?
std::make_pair(donor_iter, iter) : std::make_pair(iter, donor_iter);
- if (donor->at_min_capacity()) {
+ if (donor->below_min_capacity()) {
auto replacement = l->make_full_merge(c, r);
parent_pos.node->update(
iterator &iter)
{
LOG_PREFIX(LBATree::handle_merge);
- if (!iter.leaf.node->at_min_capacity() ||
- iter.get_depth() == 1) {
+ if (iter.get_depth() == 1 ||
+ !iter.leaf.node->below_min_capacity()) {
DEBUGT(
"no need to merge leaf, leaf size {}, depth {}",
c.trans,
DEBUGT("no need to collapse root", c.trans);
}
return seastar::stop_iteration::yes;
- } else if (pos.node->at_min_capacity()) {
+ } else if (pos.node->below_min_capacity()) {
DEBUGT(
"continuing, next node {} depth {} at min",
c.trans,
}
depth_t check_merge() const {
- if (!leaf.node->at_min_capacity()) {
+ if (!leaf.node->below_min_capacity()) {
return 0;
}
for (depth_t merge_from = 1; merge_from < get_depth(); ++merge_from) {
- if (!get_internal(merge_from + 1).node->at_min_capacity())
+ if (!get_internal(merge_from + 1).node->below_min_capacity())
return merge_from;
}
return get_depth();
resolve_relative_addrs(base);
}
+ constexpr static size_t get_min_capacity() {
+ return (get_capacity() - 1) / 2;
+ }
+
bool at_max_capacity() const {
+ assert(get_size() <= get_capacity());
return get_size() == get_capacity();
}
- bool at_min_capacity() const {
- return get_size() == (get_capacity() / 2);
+ bool below_min_capacity() const {
+ assert(get_size() >= (get_min_capacity() - 1));
+ return get_size() < get_min_capacity();
}
};
using LBAInternalNodeRef = LBAInternalNode::Ref;
std::ostream &print_detail(std::ostream &out) const final;
+ constexpr static size_t get_min_capacity() {
+ return (get_capacity() - 1) / 2;
+ }
+
bool at_max_capacity() const {
+ assert(get_size() <= get_capacity());
return get_size() == get_capacity();
}
- bool at_min_capacity() const {
- return get_size() == (get_capacity() / 2);
+ bool below_min_capacity() const {
+ assert(get_size() >= (get_min_capacity() - 1));
+ return get_size() < get_min_capacity();
}
};
using LBALeafNodeRef = TCachedExtentRef<LBALeafNode>;