Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl module to split/mask intervals

Tags:

perl

intervals

I am using the Set::IntervalTree code to compare two sets of intervals. However, I need an extra method that AFAIK is currently not implemented in this module.

I would like to have a method that splits or masks one interval into two or more. For example:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    <= [Original Interval A]
           rrrrrrrrr                    <= [Interval B to mask against A]
xxxxxxxxxxx         xxxxxxxxxxxxxxxx    <= [Resulting Intervals A1 and A2]

Any ideas if this is possible with an existing Perl module?

EDIT:

For more information, each interval can be of size 1 to 1 billion (1E9) and in each interval set there are between 1 to 1 million (1E6) intervals.

like image 515
719016 Avatar asked Jan 21 '14 17:01

719016


1 Answers

Set::IntSpan does want you want, assuming you need integer boundaries for your intervals:

#!/usr/bin/perl -w
use strict;
use Set::IntSpan;

my $A    = new   Set::IntSpan '1-1000000000';
my $B    = new   Set::IntSpan '3-5,10-20,100-200,1000-2000';
my $C    = diff $A $B;

print $C;

returns

1-2,6-9,21-99,201-999,2001-1000000000

like image 157
Jeff Snider Avatar answered Oct 18 '22 09:10

Jeff Snider