October 15th, 2011, 03:02 PM
RLE sequence, set a value
Say I have an arbitrary RLE Sequence. (For those who don't know, RLE compresses an array like [4 4 4 4 4 6 6 1 1] into [5 4 2 6 2 1]. First comes the number of a particular integer in a run, then the number itself.)
How can I determine an algorithm to set a value at a given index without decompressing the whole thing? For example, if you do set(0,1) the RLE would become [1 1 4 4 2 6 2 1]. (In set, the first value is the index, the second is the value)
I'm trying to find an efficient way to do this, right now I can just think of methods that have WAY too many if statements to be considered clean.
October 15th, 2011, 10:17 PM
Re: RLE sequence, set a value
I'd say you simply can't. What makes you think uncompressig the whole thing, then prosessing and recompressing it is no good idea? Actually, not doing that would clutter your code with all sorts of unnecessarily considered special cases (i.e. if statemetnts). One of the key issues is that changing the uncompressed data stream may change the length of the compressed stream. Also, at leat at the moment, I can't imagine any (non-malicious) reason why one would strive for an unmodified length of the modified compressed data stream.
Originally Posted by vandrop
Finally, note that RLE is no standard compression scheme and there very well also are implementations that encode blocks of unrepeated data, simply because it's obviously inefficient to encode, e.g., [1 2 3 4] as [1 1 1 2 1 3 1 4].
Last edited by Eri523; October 15th, 2011 at 10:20 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.