98532f3287
The way sparse ids interact with our flat id+attr tree is a bit wonky. Normally, with weighted trees, one entry is associated with one weight. But since our rbyd trees use id+attr pairs as keys, in theory each set of id+attr pairs should share a single weight. +-+-+-+-> id0,attr0 -. | | | '-> id0,attr1 +- weight 5 | | '-+-> id0,attr2 -' | | | | | '-> id5,attr0 -. | '-+-+-> id5,attr1 +- weight 5 | | '-> id5,attr2 -' | | | '-+-> id10,attr0 -. | '-> id10,attr1 +- weight 5 '-------> id10,attr2 -' To make this representable, we could give a single id+attr pair the weight, and make the other attrs have a weight of zero. In our current scheme, attr0 (actually LFSR_TAG_MK) is the only attr required for every id, and it has the benefit of being the first attr found during traversal. So it is the obvious choice for storing the id's effective weight. But there's still some trickiness. Keep in mind our ids are derived from the weights in the rbyd tree. So if follow intuition and implement this naively: +-+-+-+-> id0,attr0 weight 5 | | | '-> id5,attr1 weight 0 | | '-+-> id5,attr2 weight 0 | | | | | '-> id5,attr0 weight 5 | '-+-+-> id10,attr1 weight 0 | | '-> id10,attr2 weight 0 | | | '-+-> id10,attr0 weight 5 | '-> id15,attr1 weight 0 '-------> id15,attr2 weight 0 Suddenly the ids in the attr sets don't match! It may be possible to work around this with special cases for attr0, but this would complicate the code and make the presence of attr0 a strict requirement. Instead, if we associate each attr set with not the smallest id in the weight but the largest id in the weight, so id' = id+(weight-1), then our requirements work out while still keeping each attr set on the same low-level id: +-+-+-+-> id4,attr0 weight 5 | | | '-> id4,attr1 weight 0 | | '-+-> id4,attr2 weight 0 | | | | | '-> id9,attr0 weight 5 | '-+-+-> id9,attr1 weight 0 | | '-> id9,attr2 weight 0 | | | '-+-> id14,attr0 weight 5 | '-> id14,attr1 weight 0 '-------> id14,attr2 weight 0 To be blunt, this is unintuitive, and I'm worried it may be its own source of complexity/bugs. But this representation does solve the problem at hand, so I'm just going to see how it works out.