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,
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|