Well, I've got a name.  I'm just not sure if it's optimum.  For now, I'm
calling the module Array::IntSpan.  Think of it as a merger between
Set::IntSpan and a normal Perl array.  The idea is that you specify
different values for mutually exclusive ranges of integers and then you can
do lookups on arbitrary integers.

The interface consists of two methods, set_range and lookup.  The set_range
method takes three parameters - the start and end indices and the value.  It
properly deals with overlapping ranges, replacing any existing data.  The
lookup method takes a index and returns the value (if it is defined) or
undef if it isn't.  It uses an internal RLE style system (OK, $self looks
like [[start, end, value], [start, end, value], . . . .]).  It uses binary
searches for lookups.  Appending a range is O(1), but inserting is O(n)
(where n is the number of ranges), since I use splice for inserts.

I've also implemented Array::IntSpan::IP, which takes IP addresses in the
three major forms (dotted decimal, 4 byte string in network order, and as an
integer) and maps them to the later form before accessing the data.  Handy
for routing type issues (take a list of addresses and determine what subnets
they are in based on an Array::IntSpan::IP object that has a list of subnet
ranges and names - even if the subnets are of various sizes).

Anyway, I didn't see anything like this in existence.  Does such exist?  Did
I reinvent the wheel?  If not, what's a good name for it?

--Toby Everett

Reply via email to