整数编码和解码问题
我有一个很长的整数列表,我需要将其减少到一个整数。整数列表的长度可以是 0 到 300 个整数(大约)。我需要能够编码/解码。
有比查找表更好的选择吗?
I have a long list of integers, and i need to reduce this down to a single integer. The 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何将 N 位数据减少为 M 位数据(其中 M 小于 N)的技术只能适用于以某种方式冗余的输入。减少 300:1 将需要输入中存在大量冗余(例如,几乎所有数字都是零)。
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).
如果您想节省一些空间,并且 32 位整数列表在统计上聚集在某个值范围内,则可以使用整数压缩。
.NET 对 IL 程序集中的方法元数据使用整数压缩。这个想法是,如果整数通常很小(例如 1-100),您可以通过使用远少于 32 位的编码来节省空间。根据您的方案,您必须牺牲一两个来告诉压缩器/解压缩器您的值是小还是大。
请参阅此处更深入地解释 .NET 如何做到这一点。
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.