Last active
August 29, 2015 14:03
-
-
Save dbolser/43d456906084442f045b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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