数组压缩算法
我有一个 10345 字节的数组,我想压缩该数组然后解压缩,请建议我可以减小数组大小的压缩算法。我使用的是c语言,数组是unsigned char类型。
改写:有人可以建议 C/C++ 的通用压缩算法(或库)吗?
I have an array of 10345 bytes, I want to compress the array and then decompress, kindly suggest me the compression algorithm which can reduce the size of array. I am using c language, and the array is of unsigned char type.
Rephrased: Can someone suggest a general-purpose compression algorithm (or library) for C/C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
zlib
无损压缩算法
zlib
Lossless Compression Algorithms
这篇文章是一个社区维基。我不想为此得分——我已经投票决定结束这个问题。
压缩的字节数与压缩算法的选择关系不大,尽管它确实影响实现。例如,当要压缩的字节数少于 2^15 时,如果您使用 ZLib,则需要指定小于 15 的压缩级别。Zlib 中的压缩级别(两个此类参数之一)控制“回头看”词典的深度。如果你的文件小于 16k 字节,那么 32k 的回溯字典永远不会填满;在这种情况下,与将 ZLib 设置为“max”相比,在压缩的 1/15 边缘的回溯中使用少一位指针。
数据的内容才是最重要的。如果您发送的图像主要包含背景,那么您可能需要运行长度编码(例如,Windows .BMP 使用)。
如果您主要发送英文文本,那么您希望可以使用 ZLib 之类的东西,它实现了 Huffman 编码和 LZW 风格的回溯字典压缩。
如果您的数据已加密,则尝试压缩它不会成功。
如果您的数据是特定类型的信号,并且您可以容忍一些细节丢失,那么您可能需要将其转换为频率空间并仅发送主要成分。 (例如,JPEG、MP3)
This post's a community wiki. I don't want any points for this -- I've already voted to close the question.
The number of bytes to compress has very little to do with choice of compression algorithm, although it does affect the implementation. For example, when you have fewer than 2^15 bytes to compress, if you are using ZLib, you will want to specify a compression-level of less than 15. The compression-level in Zlib (one of the two such parameters) controls the depth of the "look-back" dictionary. If your file is shorter than 16k bytes, then a 32k look-back dictionary will never half-fill; in that case, use one less bit of pointer into the look-back for a 1/15th edge on the compression compared to setting ZLib to "max."
The content of the data is what matters. If you are sending images with mostly background, then you might want Run Length Encoding (used by Windows .BMP, for example).
If you are sending mostly English text, than you wish you could use something like ZLib, which implements Huffman encoding and LZW-style look-back dictionary compression.
If your data has been encrypted, then attempting to compress it will not succeed.
If your data is a particular type of signal, and you can tolerate some loss of detail, then you may want to transform it into frequency space and send only the principal components. (e.g., JPEG, MP3)