compression problem

Started by
1 comment, last by iMalc 12 years, 11 months ago
I was wondering if someone could help me with some compression.

I want to compress a variable amount of numbers up to 20 into one number.

So I could have like 1,3,7,15.

or 5, 16, 20

I want those numbers compressed into one but also want to extract them from compressed form.


I don't have any experience with compression so if anyone could help that would be awesome.
Advertisement
If the numbers are ascending and don't repeat, I guess you could use some 20bit (or more, generally 32bit) integer type and just set a bit if the corresponding number is selected or not. If the numbers are ordered or can repeat, you'll probably have to use 5 bits to represent each number. For simplicity, going with a 32bit integer type, you could store 32 / 5 bits, or approximately 6 numbers per each integer, just shift the bits into place.
The ideal method of compression depends upon several things:
What is the frequency distribution of the values? I.e. are all values from 1-20 (I assume zero is not included?) equally likely, or is it the case that the smaller the number is the more likely it is?
If the distribution is uneven then can you describe the distribution? For example is each number half as likely as the one before it (like the number of heads in a row when coin tossing).

Are duplicates possible?

Is this going to file, or across a network, or just for fitting a lot of data into RAM?

Do you want to be able to access the Nth compressed number I.e. random access, or is it okay to only be able to stream the numbers in and process them in order?

How important is size reduction vs time taken (say on a one to ten scale where one means "some reduction would be nice, but it really has to be fast" and ten means "must save every last bit as if my life depends on it".

"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement