Alex Rivera | Logout

Compress sorted integers

Asked 2009-02-07T13:15:09.910
12

I'm building a index which is just several sets of ordered 32 bit integers stored continuously in a binary file. The problem is that this file grows pretty large. I've been thinking of adding some compressions scheme but that's a bit out of my expertise. So I'm wondering, what compression algorithm would work best in this case? Also, decompression has to be fast since this index will be used to make make look ups.

Edit
Report

3 Answers

2

MSalters' answer is interesting but might distract you if you don't analyze properly. There are only 47 Fibonacci numbers that fit in 32-bits.

But he is spot on on how to properly solve the problem by analyzing the series of increments to find patterns there to compress.

Things that matter: a) Are there repeated values? If so, how often? (if important, make it part of the compression, if not make it an exception.) b) Does it look quasi-random? This also can be good as a suitable average increment can likely be found.

answered 2009-10-19T05:51:53.620
1

The conditions on the lists of integers is slightly different, but the question Compression for a unique stream of data suggests several approaches which could help you.

I'd suggest prefiltering the data into a start and a series of offsets. If you know that the offsets will reliably small you could even encode them as 1- or 2-byte quantities instead of 4-bytes. If you don't know this, each offset could still be 4 bytes, but since they will be small diffs, you'll get many more repeats than you would storing the original integers.

After prefiltering, run your output through the compression scheme of your choice - something that works on a byte level, like gzip or zlib, would probably do a really nice job.

answered 2009-02-07T13:52:19.677
0

I'd use something bog standard off the shelf before investing in your own scheme.

In Java for example you can use GZIPOutputStream to apply gzip compression.

answered 2009-02-07T13:41:01.073

Your Answer