开发者

Intger encoding and decoding problem

I have a long list of integers, and i need to reduce this down to a single integer. Th开发者_运维百科e integer list can be anywhere from 0 to 300 ints long (about). I need to be able to encode/decode.

Is there a better option than a lookup table?


Any technique for reducing N bits of data to M bits of data, where M is less than N can only work for inputs that are redundant in some way. A reduction of 300:1 would require a huge amount of redundancy in the input (e.g., almost all the numbers were zeros).


If you want to save some space and your list of 32-bit integers are statistically clustered around a certain range of values, you can use integer compression.

.NET uses integer compression for method metadata in IL assemblies. The idea is that if the integer is usually small (e.g. 1-100), you can save space by encoding it using far fewer than 32 bits. Depending on your scheme, you'll have to sacrifice a bit or two to tell the compressor/decompressor whether you have a small value or a large value.

See here for a deeper explanation of how .NET does it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜