0

I am working on the LTC algorithm to compress the data

int SIZE =256;
int data[SIZE ]={700,...};  // input dataset (original data)

After executed the LTC I get on output (compressed data) like this:

//format: "number:count" --> e.g., 511:4

700:1
812:15
511:4
117:25
905:25
117:25
905:25
117:25

How can I compute the compression ratio for this output (the compressed data)?

 // CR = Original/ compressed 
float CR = ((int)(SIZE*(sizeof(int)))/?);
lena
  • 730
  • 2
  • 11
  • 23

1 Answers1

2

How can I compute the compression ratio

// Size of one "number:count" pair.
size_t size_of_number_count = sizeof size_t + sizeof data[0];

// Number of "number:count" pairs.
size_t compressed_count = 8;

// CR = Original/ compressed 
double CR = 1.0 * sizeof data / (compressed_count * size_of_number_count);
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • Is the calculation of the `size_of_number_count` value just an example, or does it match some actual implementation? Are there any implementations that store each number:count pair in a variable-length format (so that `size_of_number_count` would not be constant over the data set)? – Ian Abbott May 19 '23 at 18:41
  • @IanAbbott A sample. As the goal is the ratio of a _compression_, it is reasonable to assume the compressed data lacks padding or unused elements. I suppose code could use a slightly more correct/pessimistic: `double CR = 1.0 * sizeof data / (compressed_count * size_of_number_count + sizeof compressed_count);`. – chux - Reinstate Monica May 19 '23 at 19:24