Best Compression algorithm for a sequence of integers

前端 未结 15 1607
离开以前
离开以前 2020-11-29 16:41

I have a large array with a range of integers that are mostly continuous, eg 1-100, 110-160, etc. All integers are positive. What would be the best algorithm to compress thi

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 17:32

    First, preprocess your list of values by taking the difference between each value and the previous one (for the first value, assume the previous one was zero). This should in your case give mostly a sequence of ones, which can be compressed much more easily by most compression algorithms.

    This is how the PNG format does to improve its compression (it does one of several difference methods followed by the same compression algorithm used by gzip).

提交回复
热议问题