Sign in to follow this  
Butabee

compression problem

Recommended Posts

Butabee    274
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
iMalc    2466
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".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this