in reply to Fast, Efficient Union and Intersection on arrays
Wall Time
barvin 54.134s
BrowserUK 26.905s
Roy Johnson 21.349s
So for those coming in by Google...
To calculate the count of intersection and union on two arrays (used by me to calculate the Jaccard Distance on the edges of a graph), pass two array references that have no internal duplicates to Roy's subroutine below. Thanks Roy.
sub get_int_uni2 {
my ($in, $jn) = @_;
my %i;
@i{@$in} = ();
my $int = grep exists $i{$_}, @$jn;
return ($int, @$in + @$jn - $int);
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fast, Efficient Union and Intersection on arrays
by perreal (Monk) on Nov 20, 2008 at 21:34 UTC |