I'm doing graph traversal and calculating the Jaccard distance on each pair of vertices. Calculating intersection and union are consuming 98% of my processing time.
I've tried Set::IntSpan, Set::Array and List::Compare, but they are all even slower than my own code. Is there a VERY fast (maybe implemented in C) way to calculate intersection and union on two arrays? Just for interest, my implementation is ($in and $jn are array refs of positive integers):
sub get_int_uni {
my ($in, $jn) = @_;
my (%int, %uni);
for my $i (@$in) {
$uni{$i}++;
}
for my $j (@$jn) {
$int{$j}++ if $uni{$j};
$uni{$j}++;
}
return ((scalar keys %int), (scalar keys %uni));
}
In reply to Fast, Efficient Union and Intersection on arrays by barvin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |