ref: 97b5e4719c3034cfd5086130adef433769e0586b
parent: 09728f26557950c4367340e97e60a12f1ae526ec
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Nov 21 23:18:08 EST 2025
gefs: fix edge case in pivot split When the first item being pulled down into a leaf fits as the first entry of the leaf, we could put the wrong value into mid: buf: 25 leaf: [10 20 30 40] if we decide to split, we could end up with 30 as the first item in the node, even though the post-split result would be: [10 20] [25 30 40] So, let's pull the mid split after we're done fully constructing both left and right, rather than when we decide to do the split.
--- a/sys/src/cmd/gefs/tree.c
+++ b/sys/src/cmd/gefs/tree.c
@@ -724,7 +724,6 @@
if((i == b->nval-2) || (i >= 2 && copied >= halfsz)){d = r;
spc = Leafspc - (halfsz + Msgmax);
- getval(b, i, mid);
}
getval(b, i, &v);
c = pullmsg(up, j, &v, &m, &full, spc);
@@ -783,6 +782,7 @@
}
p->npull = (j - up->lo);
p->op = POsplit;
+ getval(r, 0, mid);
setb(&p->nl, t, l);
setb(&p->nr, t, r);
poperror();
--
⑨