The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::MultiValued::RangeContainer - container for ranged values

VERSION

version 0.0.1_4

DESCRIPTION

Please don't use this module directly, use Data::MultiValued::Ranges.

This module implements the storage for ranged data. It's similar to Array::IntSpan, but simpler (and slower).

A range is defined by a pair of numbers, from and to, and it contains Num $x : $min <= $x < $max. undef is treated as "inf" (negative infinity if used as from or at, positive infinity if used as to).

The internal representation of a range is a hash with three keys, from to value.

METHODS

get

  my $value = $obj->get({ at => $point });

Retrieves the range that includes the given point. Throws a Data::MultiValued::Exceptions::RangeNotFound exception if no range includes the point.

get_or_create

  $obj->get_or_create({ from => $min, to => $max });

Retrieves the range that has the given extremes. If no such range exists, creates a new range, splicing any existing overlapping range, and returns it. Throws Data::MultiValued::Exceptions::BadRange if $min > $max.

clear

  $obj->clear({ from => $min, to => $max });

Removes the range that has the given extremes. If no such range exists, splices any existing overlapping range so that $obj->get({at => $point }) for any $min <= $point < $max will die.

Throws Data::MultiValued::Exceptions::BadRange if $min > $max.

all_ranges

  my @ranges = $obj->all_ranges;

Returns all the ranges defined in this object, as a list of 2-elements arrayrefs.

AUTHOR

Gianni Ceccarelli <dakkar@thenautilus.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Net-a-Porter.com.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.