tmp_mas->offset--;
return false;
}
+
return true;
}
src->end = mas->end;
if (can_rebalance_left(&tmp_mas, &parent, &src2, sd)) {
+ /* Left will be src2, right will be src */
left->min = src2.min;
right->max = src->max;
+ /* Shift split data variables */
+ sd->insert = mas->offset + src2.end + 1;
+ sd->offset = src2.end + 1;
+ sd->space = sd->split - src2.end;
+ sd->states[sd->len].info = &src2;
+ /* The first state to copy is the left node */
+ mns_mni_init(&sd->states[sd->len], left, 0, src2.end + 1);
+ sd->len++;
} else if (can_rebalance_right(&tmp_mas, &parent, &src2, sd)) {
sd->split = src2.end + sd->new_end - sd->split;
left_store = true;
/* Left will be src, right will be src2 */
left->min = src->min;
right->max = src2.max;
- } else {
- return false;
- }
-
- /* The rebalance operation will succeed. */
- sd->new_end += src2.end + 1;
- if (left_store) {
- /* Left pushes data right. */
sd->insert = mas->offset;
sd->space = sd->split;
sd->offset = 0;
} else {
- /* Right pushes data left */
- sd->insert = mas->offset + src2.end + 1;
- sd->offset = src2.end + 1;
- sd->space = sd->split - src2.end;
- sd->states[sd->len].info = &src2;
- mns_mni_init(&sd->states[sd->len], left, 0, src2.end + 1);
- sd->len++;
+ return false;
}
/*
* There can also be a split between nodes that may happen at these
* boundaries, or elsewhere.
*/
+ sd->new_end += src2.end + 1;
mt_wr_split_data(src, left, right, part, sd);
if (left_store) {
+ /* Stored to the left, copy the last of the right in src2 */
sd->states[sd->len].info = &src2;
mns_mni_init(&sd->states[sd->len], right, 0, src2.end + 1);
sd->len++;