If I've understood your data structure correctly, I've written similar code to this in the past (that code isn't mine to release I'm afraid).

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.