|Pathologically Eclectic Rubbish Lister|
Run length encode a bit vectorby Anonymous Monk
|on Jan 05, 2012 at 06:57 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
Hi, I have some large (multiple million bits) bit vectors, and I'd like to run length encode them to save storage.
Given the input: my $bv = pack 'N', 0x01020304; I'd like to get out an array
Where negative counts represent set bits and positive counts clear bits.
Searches for Perl and run length encoding all seem to turn up the rosetta stone thing of RLE strings: '"wwwbbbw" => 'w3b3w1' using regex.
I know I need to use vec(), but I keep getting lost in the state changes and end up with huge nest of ifs and garbage output.
Any help appreciated.