Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Run length encode a bit vector

by johngg (Canon)
on Jan 05, 2012 at 10:59 UTC ( [id://946361]=note: print w/replies, xml ) Need Help??


in reply to Run length encode a bit vector

I'm not sure your expected output is making sense as I think you have probably mis-counted the number of zeros in the second term because there is actually a run of eight zeros there.

$ perl -E 'say unpack q{b*}, pack q{N}, 0x01020304;' 10000000010000001100000000100000

As well as that, you seem to be parsing your data with the low-order bit first in each byte even though you have packed in network order. I would expect you bit vector to look like this

$ perl -E 'say unpack q{B*}, pack q{N}, 0x01020304;' 00000001000000100000001100000100

with expected output

7, -1, 6, -1, 7, -2, 5, -1, 2

Perhaps you could clarify your requirement.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Run length encode a bit vector
by Anonymous Monk on Jan 05, 2012 at 12:24 UTC
    -- I think you have probably mis-counted the number of zeros in the second term because there is actually a run of eight zeros there.

    Yes. I miscounted.

    -- As well as that, you seem to be parsing your data with the low-order bit first in each byte even though you have packed in network order.

    Actually irrelevant as it is just sample data. The actual vector to be compressed is built with vec(), so 'b' is the right template.

      Actually irrelevant as it is just sample data.

      Can you please provide an example of relevant data and the relevant output you expect from that data?

      The actual vector to be compressed is built with vec()...

      Can you say why vec must be used? pack/unpack seem better suited.

        -- Can you please provide an example of relevant data and the relevant output you expect from that data?

        You want me to post a 31,156,327 byte bit-vector that represents just under a quarter of a billion boolean states?

        The vector is just a string of bits. Packing a integer to provide a sample was convenient. The ordering of the bits was irrelevant.

        The important factor was showing how the rle was to be encoded. -- Can you say why vec must be used?

        Pack (or any other means) is fine for the rle, but the original vector is built with vec() so the appropriate pack template for accessing the bits in the same order as they were constructed is 'b*'.

        The downside of using unpack 'b*' during the rle, is it expands the 31MB vector to a 250 MB string.

        On the other hand, vec() can process the 31MB without expanding it at all.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found