Tweaked diverged red stitching to use lfsr_rbyd_p_red
There's a hidden story here where I tried to explore yellow stitching on
top of red stiching, which may or may not bring the worst-case 2-3-4
height down from ~2x to ~1.3x. But this made the system more complex and
harder to reason about balance-wise (we risk destabilizing the tree if
we remove more alts than we stich), so droping for now. May revisit.
In theory this saves code, but in practice it does not. Still, I think
it's a bit more readable and moves all the recoloring preconditions into
one place:
code stack
before: 33976 2880
after: 33980 (+0.0%) 2880 (+0.0%)
This commit is contained in:
@@ -2997,16 +2997,6 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
||||
p_alts[0], p_weights[0],
|
||||
&lower_rid, &upper_rid,
|
||||
&lower_tag, &upper_tag);
|
||||
|
||||
// if we diverged, stitch our paths together with alternating
|
||||
// red alts, this gives us an optimal ternary tree if we
|
||||
// started with a binary tree, but the above recoloring makes
|
||||
// this not optimal
|
||||
if (lfsr_tag_hasdiverged(tag_)
|
||||
&& p_alts[0]
|
||||
&& lfsr_tag_isblack(p_alts[1])) {
|
||||
p_alts[0] |= LFSR_TAG_R;
|
||||
}
|
||||
}
|
||||
|
||||
// push alt onto our queue
|
||||
@@ -3017,6 +3007,14 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
||||
return err;
|
||||
}
|
||||
|
||||
// if we diverged, stitch our paths together with alternating
|
||||
// red alts, this gives us an optimal ternary tree if we
|
||||
// started with a binary tree, but the above recoloring makes
|
||||
// this not optimal
|
||||
if (lfsr_tag_hasdiverged(tag_) && lfsr_tag_isblack(p_alts[2])) {
|
||||
lfsr_rbyd_p_red(p_alts, p_weights, p_jumps);
|
||||
}
|
||||
|
||||
// continue to next alt
|
||||
graft = branch;
|
||||
branch = branch_;
|
||||
|
||||
Reference in New Issue
Block a user