Questions tagged [run-length-encoding]

Run-length encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run.

Run-length encoding is most useful on data that contains many such runs: for example, simple graphic images such as icons, line drawings, and animations. It is not useful with files that don't have many runs as it could greatly increase the file size.

254 questions
3
votes
3 answers

Python Compression Run Length encoding

I am trying to learn about run length encoding and I found this challenge online that I cant do. It requires you to write a compression function called compression(strg) that takes a binary string strg of length 64 as input and returns another…
user1681664
  • 1,771
  • 8
  • 28
  • 53
3
votes
6 answers

Run length encoding using O(1) space

Can we do the run-length encoding in place(assuming the input array is very large) We can do for the cases such as AAAABBBBCCCCDDDD A4B4C4D4 But how to do it for the case such as ABCDEFG? where the output would be A1B1C1D1E1F1G1
Luv
  • 5,381
  • 9
  • 48
  • 61
2
votes
1 answer

Indicating the end of a raw data chunk in an RLE algorithm that can contain all byte values

I'm writing an RLE algorithm in C# that can work on any file as input. The approach to encoding I'm taking is as follows: An RLE packet contains 1 byte for the length and 1 byte for the value. For example, if the byte 0xFF appeared 3 times in a row,…
Wolf
  • 53
  • 6
2
votes
2 answers

Compressed SortedSet implementation

I need to store a large number of Long values in a SortedSet implementation in a space-efficient manner. I was considering bit-set implementations and discovered Javaewah. However, the API expects int values rather than longs. Can anyone recommend…
Adamski
  • 54,009
  • 15
  • 113
  • 152
2
votes
2 answers

how can i convert a string to tuple

hello we have to create a code with turns for example "1T3e1s1t" into [(1,'T'),(3,'e'),(1,'s'),(1,'t')] here is my code unformat :: String -> [(Int, Char)] unformat [] = [] unformat (x:xs) = [(unformat' + 1, x)] ++ unformat xss where …
2
votes
2 answers

Combinatorics: St. Peter's Game algorithm

There's a combinatorics puzzle (as mentioned in Mathematics From the Birth of Numbers by Jan Gullberg) where if you line up fifteen members from two categories each (e.g. fifteen of category 0 and fifteen of category 1 for a total of 30 elements)…
147pm
  • 2,137
  • 18
  • 28
2
votes
1 answer

Is there a better way to introduce run-length id in the presence of NA?

I have this data: df <- data.frame( Sequ = c(NA, 8, 8, NA, 1, 1, 1, NA, NA, NA, 22, 22, NA), Q = c(NA, "q_x", "", NA, "q_2", "", "", NA, NA, NA, "q_xyz", "", NA) ) What I'd like to do is introduce a correct run-length id in Sequ where it is not…
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
2
votes
1 answer

R How to Generate Sequences in a Tibble Given Start and End Points

I can't think how to do this in a tidy fashion. I have a table as follows: tibble( Min = c(1, 5, 12, 13, 19), Max = c(3, 11, 12, 14, 19), Value = c("a", "bb", "c", "d", "e" ) ) and I want to generate another table from it as shown…
James Bejon
  • 189
  • 5
2
votes
3 answers

Select first row per run by group

I have data with a grouping variable (ID) and some values (type): ID <- c("1", "1", "1", "1", "2", "2", "2", "2", "3", "3", "3", "3") type <- c("1", "3", "3", "2", "3", "3", "1", "1", "1", "2", "2", "1") dat <- data.frame(ID,type) Within each ID,…
Astor
  • 37
  • 5
2
votes
1 answer

RLE implementation failing every once in a while

I implemented the following two functions for RLE compression of binary files. char* RLEcompress(char* data, size_t origSize, size_t* compressedSize) { char* ret = calloc(2 * origSize, 1); size_t retIdx = 0, inIdx = 0; size_t retSize =…
Samuele B.
  • 481
  • 1
  • 6
  • 29
2
votes
1 answer

Add index to runs of equal values, accounting for NA

This an example of my data: df <- data.frame(dyad = c("a", "a", "b", NA, "c", NA, "c", "b")) df # dyad # 1 a # 2 a # 3 b # 4 # 5 c # 6 # 7 c # 8 b I want to create an index for runs consecutive runs of dyad that are…
valo
  • 25
  • 5
2
votes
1 answer

Problem with printing the correct number of same characters.RLE in C

I am having difficulties printing out the correct number of character in a RLE program. I have already made it work with arrays and Im looking for a different approach.Here is the code : #include int main () { char elem,elem1; …
alex01011
  • 1,670
  • 2
  • 5
  • 17
2
votes
2 answers

R group_by() + rleid() equivalent in Python

I've got a following data frame in Python: df = pd.DataFrame.from_dict({'measurement_id': np.repeat([1, 2], [6, 6]), 'min': np.concatenate([np.repeat([1, 2, 3], [2, 2, 2]), …
jakes
  • 1,964
  • 3
  • 18
  • 50
2
votes
0 answers

How to count unchanged occurrence of values within a group

Let's assume I've got a DataFrame as below: import pandas as pd import numpy as np df = pd.DataFrame.from_dict({'measurement_id': np.repeat([1, 2], [30, 30]), 'min': np.concatenate([np.repeat([1, 2, 3, 4, 5], [6, 6, 6,…
jakes
  • 1,964
  • 3
  • 18
  • 50
2
votes
2 answers

How to find the longest duplicate sequence in a tibble column?

I updated my question because I need one more column to my output tible. I have the following tibble: library(tibble) my_tbl <- tribble( ~year, ~event_id, ~winner_id, 2011, "A", 4322, 2012, "A", 4322, 2013, "A", …
lmcjfal
  • 85
  • 5