mas->last = r_max;
// if this one is null the next and prev are not.
} else {
- // Check prev slot if we are overwriting the start.
- if (mas->index == r_min && mas->offset &&
- !slots[mas->offset - 1]) {
- mas->offset--;
- r_min = mas->index = mas_safe_min(mas, pivots,
- mas->offset);
- r_max = pivots[mas->offset];
- }
-
// Check next slot if we are overwriting the end.
- if (mas->last == r_max && !slots[mas->offset + 1]) {
- mas->last = pivots[mas->offset + 1];
- }
- else if (mas->last > r_max) { // expand over this slot if necessary.
+ if ((mas->last == r_max) && !slots[mas->offset + 1]) {
+ if (mas->offset < mt_pivots[mt] - 1 &&
+ pivots[mas->offset + 1])
+ mas->last = pivots[mas->offset + 1];
+ else
+ mas->last = mas->max;
+ } else if (mas->last > r_max) { // expand over this slot if necessary.
unsigned long piv;
+
do {
piv = _mas_safe_pivot(mas, pivots,
++offset_end, mt);
- } while (mas->last > piv);
+ } while (mas->last >= piv);
if (!slots[offset_end])
mas->last = piv;
}
+
+ // Check prev slot if we are overwriting the start.
+ if (mas->index == r_min && mas->offset &&
+ !slots[mas->offset - 1]) {
+ mas->offset--;
+ r_min = mas->index = mas_safe_min(mas, pivots,
+ mas->offset);
+ r_max = pivots[mas->offset];
+ }
}
}