}
static inline struct maple_enode
-*mas_b_node_ma_node(struct ma_state *mas, struct maple_big_node *b_node)
+*mas_new_ma_node(struct ma_state *mas, struct maple_big_node *b_node)
{
return mt_mk_node(ma_mnode_ptr(mas_next_alloc(mas)), b_node->type);
}
unsigned char split = 0;
unsigned char slot_cnt = mt_slots[b_node->type];
- *left = mas_b_node_ma_node(mas, b_node);
+ *left = mas_new_ma_node(mas, b_node);
*right = NULL;
*middle = NULL;
*mid_split = 0;
split = b_node->b_end;
} else {
split = mab_calc_split(b_node, mid_split);
- *right = mas_b_node_ma_node(mas, b_node);
+ *right = mas_new_ma_node(mas, b_node);
}
if (*mid_split)
- *middle = mas_b_node_ma_node(mas, b_node);
+ *middle = mas_new_ma_node(mas, b_node);
return split;
split = mas_mab_to_node(mas, mast->bn, &left, &right, &middle,
&mid_split);
mast_set_split_parents(mast, left, right, split);
-
mast_cp_to_nodes(mast, left, middle, right, split, mid_split);
/* Copy data from next level in the tree to mast->bn from next iteration */
MA_TOPIARY(mat, mas->tree);
-
// Allocation failures will happen early.
- // TODO: Increase this by one when optimizing with a rebalance.
mas_node_cnt(mas, 1 + mas->full_cnt * 2);
if (mas_is_err(mas))
return 0;
- /* At the start of the loop, the maple state points to the leaf that
- * needs to be split. The loop walks up and splits all nodes that need
- * to be split. Obviously it will overflow nodes that need to be split,
- * so leaf is split into two and then placed in a maple_big_node which
- * has enough space. Each iteration after that will use the
- * maple_big_node data to split equally left and right until the height
- * is larger than mas->full_cnt which will place the maple_big_node data
- * into the highest common ancestor necessary to be modified (which may
- * be a new root).
- */
while (height++ <= mas->full_cnt) {
unsigned char mid_split;
- unsigned char slot_cnt = mt_slot_count(mas->node); /* should be full. */
+ unsigned char slot_cnt = mt_slot_count(mas->node);
bool cp = true;
b_node->type = mte_node_type(mas->node);
/* Only a single node is used here, could be root.
* Big_node should just fit in a single node.
*/
- ancestor = mas_b_node_ma_node(mas, b_node);
- // Set the parents
+ ancestor = mas_new_ma_node(mas, b_node);
mte_set_parent(l_mas.node, ancestor,
mas_get_slot(&l_mas));
mte_set_parent(r_mas.node, ancestor,
b_node->min = mas->min;
mas_dup_state(&l_mas, mas);
mas_dup_state(&r_mas, mas);
- l_mas.node = mas_b_node_ma_node(mas, b_node);
- r_mas.node = mas_b_node_ma_node(mas, b_node);
+ l_mas.node = mas_new_ma_node(mas, b_node);
+ r_mas.node = mas_new_ma_node(mas, b_node);
if (mte_is_leaf(mas->node)) {
split = mab_calc_split(b_node, &mid_split);
if (split < slot_cnt)