Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: vec overflow?

by BrowserUk (Pope)
on Jun 25, 2013 at 00:58 UTC ( #1040501=note: print w/ replies, xml ) Need Help??


in reply to vec overflow?

Is this a problem with vec? My Perl build? My syntax? Any workarounds?

It's a problem with vec. Internally it is using a signed 32-bit values, even on 64-bit builds.

One workaround I've used is to break the vector into subsections and use bitmasking to select the appropriate one:

@vecs = ( chr(0)x2**29 ) x 8;; $n = 2**31; vec( $vecs[ $n >> 29 ], $n & 0x1fffffff, 1 ) = 1;;

Not very satisfactory, but workable.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: vec overflow?
Download Code
Re^2: vec overflow?
by Anonymous Monk on Jun 25, 2013 at 01:07 UTC
    Thanks very much. Good to know.

      Another workaround that is useful if your algorithm benefits from having a single contiguous bitvector -- for example if you want to count the set bits quickly using my $popcount = unpack '%32b*', $bitvector; -- is to nest calls to vec. Eg:

      vec( vec( $bitvector, $n >> 5, 64 ), $n & 0x1f, 1 ) = 1;

      Theoretically, as neither offset breaches the 2**31-1 barrier, this can allow you to address bitvectors up to 16GB/137 billion bits, though I don't have enough memory to try it.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040501]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-07-13 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (244 votes), past polls