Skip to content

Instantly share code, notes, and snippets.

@dbolser
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbolser/43d456906084442f045b to your computer and use it in GitHub Desktop.
Save dbolser/43d456906084442f045b to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
## Easy manipulation of sets of integers (arbitrary intervals)
use Set::IntRange;
## Create two sets to play with
my $set_len = 1000000000;
my $set_a = Set::IntRange->new(1, $set_len);
my $set_b = Set::IntRange->new(1, $set_len);
## Create a few k 1000 long ranges in both...
my $range_len = 1000;
for (1..5000){
my $ra = int(rand($set_len-$range_len));
$set_a->Interval_Fill($ra,$ra+$range_len);
my $rb = int(rand($set_len-$range_len));
$set_b->Interval_Fill($rb,$rb+$range_len);
}
## Now find the size of the union
my $set_u = Set::IntRange->new(1, $set_len);
$set_u->Union($set_a, $set_b);
print $set_u->Norm, "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment