in reply to Need a faster way to find matches
foreach my $i1 (@LongListOfIntegers) { ($i1 & $_)==1 and undef $MatchedIntegers{$i1}{$_} foreach @LongListOfIntegers; }
foreach my $i1 (@LongListOfIntegers) { use integer; ($i1 & $_) == 1 and undef $MatchedIntegers{$i1}{$_} foreach @LongListOfIntegers; }
@LongListOfIntegers = grep $_ &1, @LongListOfIntegers; foreach my $i1 (@LongListOfIntegers) { use integer; ($i1 & $_) == 1 and undef $MatchedIntegers{$i1}{$_} foreach @LongListOfIntegers; }
Beyond that, any kind of categorisation of the values by the bits they have set (other than the LSB) will take far longer to set up.
It even seems unlikely that you could save much time by moving this into (Inline)C, given you want a hash as the result. To be honest 2 seconds for 16 million comparisons doesn't seem too bad.
Update: There's probably no need to have results for $x & $y and $y & $x in the hash, and even if there is, there's no need to test both. So,
@LongListOfIntegers = grep $_ &1, @LongListOfIntegers; foreach my $i1 ( 0 .. $#LongListOfIntegers) { use integer; my $v = $LongListOfIntegers[ $i1 ]; ($v & $_) == 1 and undef $MatchedIntegers{$i1}{$_} foreach @LongListOfIntegers[ $i1+1 .. $#LongListOfIntegers ]; }
Will save a bit more, though not as much as you'd think.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need a faster way to find matches
by remzak (Acolyte) on Jan 17, 2010 at 17:44 UTC | |
by remzak (Acolyte) on Jan 17, 2010 at 19:29 UTC | |
by repellent (Priest) on Jan 18, 2010 at 04:12 UTC | |
by remzak (Acolyte) on Jan 18, 2010 at 21:18 UTC |