in reply to improving the speed
With the same assumption as moritz's (that neither list has duplicate entries), you might try this:
sub Intersection { my ($refA, $refB) = @_; my %B; @B{@$refB} = (1) x @$refB; # hash the second list my $intersects; for(@$refA) { ++$intersects if exists $B{$_} # 'exists' is fast! } return $intersects; }
|
|---|