The initial code was brittle as hell, in that it was hard to fix a bug without introducing others. I'd *really* recommend a good set of unit tests for this data type.
There are a lot of different cases to consider, with edge cases where the ends of the unions are equal, overlap in different ways, are subsets, proper subsets etc.
However, I've also written some related code (not identical, this is for a half open interval, so the top endpoint isn't included) as part of exmap. If you're interested, it's Range.cpp/Range.hpp in there, with the tests in t_range.cpp.
In fact now I come to think of it, there's a perl version in there too, in the perl-deprecated directory, "Range.pm and test-range.pl".
If it's of any use, lift anything you like from that tarball. That project is GPL'd. (If you'd like it under Artistic License let me know, I'm the author and can re-license if required).
(Edit - can you steal the unit tests from Algorithm::InversionList? It's often quite easy to translate unit tests from one language to another)
In reply to Re: Inversion list prototype
by jbert
in thread Inversion list prototype
by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |