/*
* mas_data_end() - Find the end of the data (slot).
+ * @mas: the maple state
+ * @type: the type of maple node
*
- * @mas - the maple state
- * @type - the type of maple node
+ * Returns: The zero indexed last slot with data (may be null).
*/
static inline unsigned char mas_data_end(const struct ma_state *mas)
-
{
- int slot = 0;
+ unsigned char slot = 0;
enum maple_type type = mte_node_type(mas->node);
unsigned long piv = mas->min;
*/
static inline bool mas_next_sibling(struct ma_state *mas)
{
- unsigned char p_end, p_slot = mte_parent_slot(mas->node);
+ unsigned char p_slot = mte_parent_slot(mas->node) + 1;
MA_STATE(parent, mas->tree, mas->index, mas->last);
mas_dup_state(&parent, mas);
mas_ascend(&parent);
- p_end = mas_data_end(&parent);
+ if (p_slot == mt_slot_count(parent.node))
+ return false;
- if (p_end == p_slot)
+ if (!mas_get_slot(&parent, p_slot))
return false;
mas_dup_state(mas, &parent);
- mas_set_offset(mas, p_slot + 1);
+ mas_set_offset(mas, p_slot);
mas_descend(mas);
return true;
}
struct maple_enode *old_r)
{
unsigned char b_end = mast->bn->b_end;
- unsigned char end = mas_data_end(mast->orig_r);
- mas_mab_cp(mast->orig_r, 0, end, mast->bn, b_end);
+ mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node),
+ mast->bn, b_end);
mat_add(mast->free, old_r);
mast->orig_r->last = mast->orig_r->max;
if (old_r == mast->orig_l->node)
return;
mas_mab_cp(mast->orig_r, mas_offset(mast->orig_r) + 1,
- mas_data_end(mast->orig_r), mast->bn, mast->bn->b_end);
+ mt_slot_count(mast->orig_r->node), mast->bn,
+ mast->bn->b_end);
mast->orig_r->last = mast->orig_r->max;
}
mas_dup_state(&r_mas, mas);
if (mas_next_sibling(&r_mas)) {
- mas_mab_cp(&r_mas, 0, mas_data_end(&r_mas), b_node, b_end);
+ MT_BUG_ON(r_mas.tree, mas_is_none(&r_mas));
+ mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end);
r_mas.last = r_mas.index = r_mas.max;
} else {
// Copy l_mas and store the value in b_node.
b_node.b_end = mas_store_b_node(&l_mas, &b_node, entry);
// Copy r_mas into b_node.
- mas_mab_cp(&r_mas, mas_offset(&r_mas), mas_data_end(&r_mas), &b_node,
- b_node.b_end + 1);
+ mas_mab_cp(&r_mas, mas_offset(&r_mas), mt_slot_count(r_mas.node),
+ &b_node, b_node.b_end + 1);
// Stop spanning searches by searching for just index.
l_mas.index = l_mas.last = mas->index;
// Calc the number of iterations of combining and splitting that will