* @left: The node information of the left destination
* @right: The node information of the right destination
* @ma_part: The node part being inserted
- * @split: The split location referenced by the destination size
+ * @split: The split location referenced by the destination data
* @insert: The location of the insert start for @ma_part
* @size: The targeted size of the left node
- * @offset: The starting offset into the destination
- * @node_ins_end: The offset in the source the insert ends
+ * @offset: The starting offset into the destination data (may be larger than
+ * the node)
+ * @node_ins_end: The offset in the node data that the insert ends
* @total_data: The total size of the data being stored
* @state: The maple node state array
* @i: The number of existing states
unsigned char node_off, part_off;
struct ma_node_info *to;
+ /* Offset into the destination data where the insert ends */
insert_end = insert + ma_part->size - 1;
to = left;
node_off = 0; /* src */
i++;
}
-
- /*
- * Offset indexed into new data
- * split indexed into new data
- * size is the remainder of the data requested to this node
- */
-
/*
* There are two splits of src, at insert and insert_end.
* There can also be a split between nodes that may happen at these
mas->depth = height;
/* First split the leaves */
+ mni_mas_init(&src, mas);
mni_node_init(&left, mas_pop_node(mas), wr_mas->type);
mni_node_init(&right, mas_pop_node(mas), wr_mas->type);
- mni_mas_init(&src, mas);
- mns_node_part_leaf_init(&ma_part, wr_mas, &src);
- total = mas->end + ma_part.size;
if (mt_is_alloc(mas->tree))
right.alloc = left.alloc = true;
+ mns_node_part_leaf_init(&ma_part, wr_mas, &src);
+ total = mas->end + ma_part.size; /* - skip + 1 */
if (height > 1 && mas_wr_try_rebalance(mas, &src, total, &left,
&right, &ma_part, wr_mas->offset_end))
goto rebalanced;
split = (total + 1) / 2;
- left.min = mas->min;
- right.max = mas->max;
+ left.min = src.min;
+ right.max = src.max;
i = mt_wr_split_data(&src, &left, &right, &ma_part, split,
mas->offset, split, 0, wr_mas->offset_end,
total, state, 0);
mns_assemble(state, i);
mni_finalise(&left);
mni_finalise(&right);
- mni_node_part_init(&ma_part, &left, &right);
- if (height == 1) {
+ if (height == 1)
goto new_root;
- }
- //printk("%d height is %d\n", __LINE__, height);
while (--height) {
+ mni_node_part_init(&ma_part, &left, &right);
mas_wr_ascend_init(mas, &src);
mas->end = src.end;
total = mas->end + 1;
mns_assemble(state, i);
mni_finalise(&left);
mni_finalise(&right);
- mni_node_part_init(&ma_part, &left, &right);
}
new_root:
+ mni_node_part_init(&ma_part, &left, &right);
/* Converged on new root */
mas->depth++;
src.insert_off = mas->offset = 0;