O( M+N + SIGMA( 2^3+2^4+...+2^n>N) + SIGMA( 2^3+...+2^m >M ) + MIN(N,M) )
memory for 1st hash memory for 2nd hash memory for 1 array*
## (*assuming you chose the smallest array to use with the 2hash/1 list method)
####
O( M+N + SIGMA( 2^3+2^4+...+2^n>N) + N + M) )
memory for smallest hash memory for the two arrays
## for the 1 hash/2 arrays method.
####
C:\test>unionIntersect.pl -N=1e6 -MAX=27
s/iter barvin roy buk buk2
barvin 8.58 -- -43% -58% -64%
roy 4.86 77% -- -26% -37%
buk 3.59 139% 35% -- -15%
buk2 3.05 182% 60% 18% --
####
C:\test>unionIntersect.pl -N=5e5 -MAX=27
s/iter barvin buk roy buk2
barvin 3.87 -- -28% -40% -50%
buk 2.80 39% -- -17% -30%
roy 2.33 66% 20% -- -16%
buk2 1.95 98% 43% 19% --
####
sub buk2{
my( $aRef, $bRef ) = @_;
my( $aBits, $bBits );
for( $aBits, $bBits ) {
local $\;
open my $ram, '>', \$_;
seek $ram, $MAX-1, 0;
print $ram chr(0);
close $ram;
}
vec( $aBits, $_, 1 ) = 1 for @$aRef;
vec( $bBits, $_, 1 ) = 1 for @$bRef;
my $iCount = unpack '%32b*', ( $aBits & $bBits );
my $uCount = @$aRef + @$bRef - $iCount;
$aBits = $bBits = '';
print 'buk2: ', $iCount, ' : ', $uCount if $SHOW;
return( $iCount, $uCount );
}