I'm new to perl, yet an old dog with other languages. I'm looking for a way to scan through a very long list of 64-bit integers and find all pairs in the list that share only the least significant bit being set (($num1 & $num2)==1).
The code below takes much too long.
# find all integers in the list that do not share any bits except the
+lsb.
my %MatchedIntegers=(); #my output
foreach my $i1 (@LongListOfIntegers)
{
foreach (@LongListOfIntegers)
{ #if a match (only least significant bit overlaps),
# add to hash of hash, I don't care about the value.
$MatchedIntegers{$i1}{$_}=() if (($i1 & $_) == 1) ;
}
}
Any ideas? It seems that this should be a very fast thing to do. For a list of ~4,000 values, it takes 2 seconds. I want to keep the code in perl (not link to C/C++). I need the output in a hash table, but it could be a hash of arrays instead of a hash of hashes.
Thanks,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.