I don't know of one, nor did a quick search of Google or CPAN turn up one.

If you have a concrete problem to solve, my strongest piece of advice is to solve it without worrying about efficiency. What you should do is create a class for searching intervals, and implement it in the stupidest way possible - as an array of arrays that you grep through to find your intervals. Give this class a good API, and develop the rest of your program using it. Odds are that, inefficient as it is, performance will be fine.

Junior programmers often have an involuntary shudder when writing such deliberately inefficient code. Try to suppress that reaction. Yes, it is horribly inefficient. But writing "just enough to do the job" is an essential part of exploratory programming, and knowing how and when to do it is a very valuable skill. It is essential to use a good interface so that you can improve the code later if needed, but don't get sidetracked solving problems you don't have until you have them.

After you're finished your program if performance is a real issue, then you can write an efficient one. To do that I would suggest starting by reading about B-Trees in Perl, and then modify the B-Tree algorithm to add the maximum heights, resulting in an Augmented Tree implementation.

The final implementation should be very similar to the B-Tree code in that article with one additional attribute in your nodes, but figuring out the details is likely to be an "educational experience". A good set of tests will be very helpful in tracking down your likely mistakes. If you're happy with the result, I'd suggest contributing it to CPAN.

If your efficient solution is not efficient enough, then you can interface to an existing library in a lower level language.

Based on past experience I would be willing to bet money that you'll find that the naive and inefficient version is sufficient for your needs.


In reply to Re: Interval Tree by tilly
in thread Interval Tree by Anonymous Monk

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.