Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Run length encode a bit vectorby johngg (Canon) |
on Jan 05, 2012 at 23:46 UTC ( [id://946498]=note: print w/replies, xml ) | Need Help?? |
Because you are compressing sequences of bits rather than bytes I am not convinced that you will see a saving in space. It will depend on whether you have longish sequences of contiguous ones or zeros. If there are many short runs or singletons, your array of counts is likely to take more space than the vector. Unless I'm misunderstanding something, you need to have runs of more than eight ones or zeros before you break even if representing each count as a signed character; it gets worse if having to use shorts or longs. Packing the array as signed characters would cater for up to
The output.
As I say, I may be misunderstanding something or your vector might consist of very long contiguous runs. I'd be interested to know whether you will see a benefit using RLE. Update: Corrected the senior moment with maximum -ve and +ve values that can be held in a byte. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|