RLE sequence, set a value
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: RLE sequence, set a value

  1. #1
    Join Date
    Oct 2011

    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.


  2. #2
    Join Date
    Jun 2010

    Re: RLE sequence, set a value

    Quote Originally Posted by vandrop View Post
    How can I determine an algorithm to set a value at a given index without decompressing the whole thing?
    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.

    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 09: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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a Codeguru.com survey!

On-Demand Webinars (sponsored)