guint pnext,
guint version)
{
- guint rm, i, nv, next, nextv, lnext, rnext;
+ guint rm, i, nv, next, nextv, lnext, rnext, ret;
if (!node)
return 0;
nv = node->nv;
+ ret = 0;
rm = 0;
for (i = nv > 1 ? 1 : 0; i < nv && node->v[i].version <= version; i = next)
{
if (next < nv && node->v[i].right &&
node->v[next].right == node->v[i].right &&
- (!pnext || node->v[next].version < pnext))
+ (!pnext || node->v[next].version <= pnext))
rnext = node->v[next].version;
else if (next == nv || node->v[next].version > pnext)
rnext = pnext;
rnext = g_tree_node_delete_versions (tree, node->v[i].right, rnext,
nextv);
+ /* smallest non-zero of pnext, rnext, and lnext (or zero if all 3 are) */
nextv = MIN ((pnext ? pnext : (lnext ? lnext : rnext)),
MIN ((lnext ? lnext : (rnext ? rnext : pnext)),
(rnext ? rnext : (lnext ? lnext : pnext))));
if (nextv && (next == nv || node->v[next].version > nextv))
{ /* leave this one behind as there are more pointers coming here */
- node->v[i].version = nextv;
+ ret = node->v[i].version = nextv;
break;
}
- /* am i a root? */
-// if (node->v[i].parent == NULL)
-// {
-// GTreeRootVersion *rv;
-//
-// rv = g_tree_root_find_version (tree, node->v[i].version);
-// rv->root = NULL;
-// }
-
++rm;
}
node = NULL;
}
- //nextv = (node && node->nv ?
- // (node->nv > 1 ? node->v[1].version : node->v[0].version) : 0);
- //if (nextv > version)
- // nextv = 0;
- //return nextv;
+ /* if we saved a version here, then it's because a child still needs it
+ or the parent still needs it. if the child needs it, then we will
+ still have a pointer back to the parent, so it needs to also know. so
+ either way the parent needs it.
+ if we did not save a version, but the parent needs us to stick around for
+ something, then we can let it know that we did
+ */
+ if (!ret && node && pnext)
+ {
+ g_assert (node->v[node->nv > 1 ? 1 : 0].version == pnext);
+ ret = pnext;
+ }
- /* return the lowest version left in the node, or 0 if its gone */
- return (!node || !node->nv ? 0 :
- (node->nv > 1 ? node->v[1].version : node->v[0].version));
+ return ret;
}
void
i = tree->nroots > 1 ? 1 : 0;
next = next_version (i, tree->nroots);
while (i < tree->nroots &&
- tree->roots[i].version <= tree->lowest_version)
+ tree->roots[i].version < tree->lowest_version)
{
guint nextv, v;
l = g_tree_node_delete_versions (tree, tree->root(i), nextv, v);
g_assert (l == 0 || l > v);
- if (next == tree->nroots ||
- tree->roots[next].version > tree->lowest_version)
+ if (l > v)
tree->roots[i].version = l;
else
- ++rm;
+ {
+ ++rm;
+ keep = next;
+ }
- keep = i;
i = next;
next = next_version (i, tree->nroots);
}