Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a module which implements a kind of binary search for intervals. Given a collection of ranges and associated items (like (1,5,"foo") and (-1, 3,"bar")), you can search by a query range to get everything which overlaps it (like an R-tree in 1 dimension). I wrote it at work to efficiently query genes and other features on chromosomes by location. Snippet below shows it's interface.

Two questions: Does something like this already exist on CPAN? (I didn't find anything). And if not, what should I name it, if I were to upload it? I'm thinking Tree::Interval, Tree::Range, Tree::Binary::Range, Tree::Binary::Interval, Search::Range or Search::Internal... Tree describes what it is, but Search describes what it does.

Thankya.
use Tree::Range; my $tr = Tree::Range->new(); $tr->add(10,20,"a"); $tr->add(15,25,"b"); $tr->add(50,67,"c"); $tr->add(22,49,"d"); $tr->finalize(); print join ",", $tr->search(19,23); # "a,b,d"

Replies are listed 'Best First'.
Re: What should I name my binary range tree module?
by JavaFan (Canon) on May 29, 2011 at 09:33 UTC
    I'd use an Algorithm:: or DataStructure:: prefix. I cannot determine from your description whether you are implementing a segment tree, an interval tree, or something else. If for instance of the first, I'd name it DataStructure::SegmentTree, or DataStructure::Tree::Segment.

    I would not go for a top level Tree::

      I think I'll go for the Algorithm:: namespace, b/c I'm not really sure what structure it is, though it seems closer to a Segment tree from wikipedia'ing.

      (What I do is, given a list of intervals, I sort them by midpoint, and join adjacent intervals into parent nodes with interval (min(children's starts), max(children's ends)). The idea being that every node encompasses it's descendants, so that you can query by traversing nodes overlapping the query interval.)

Re: What should I name my binary range tree module?
by Gulliver (Monk) on May 29, 2011 at 12:14 UTC

    Module authors are encouraged to discuss module names and namespaces before uploading.

    I found the following at this page. http://www.cpan.org/modules/04pause.html

    Please, talk to other people (comp.lang.perl.modules, modules@perl.org or any mailing list that fits your problem domain) before you decide upon the namespace you're going to use for your module. Usually it's not considered the perl way to have bureaucratic conventions, but when it comes to namespace pollution, there is the need of coordination. Just like the InterNIC has to care for unique names for internet hosts, somebody has to (sort of) guarantee uniqueness, consistency, and sanity of module names. search.cpan.org is the place where all currently uploaded modules can be found and the email address modules@perl.org is an alias for a hand full of experienced volunteers who try to give advice for the appropriate namespace for your modules.
    Please consider the namespace you're going to occupy with all due sensitivity. Discuss it in the appropriate fora. Read what the perlmodlib manpage has to say about this. Reading these sections carefully will help you and us to greatly improve the usefulness of the CPAN and avoid cumbersome renaming at a later date.