Jar*_*edC 2 c c++ compression lzf
我在我的应用程序中使用libLZF进行压缩.在文档中,有一条关注我的评论:
lzf_compress might use different algorithms on different systems and
even different runs, thus might result in different compressed strings
depending on the phase of the moon or similar factors.
Run Code Online (Sandbox Code Playgroud)
我打算比较压缩数据以了解输入是否相同.显然,如果使用不同的算法,则压缩数据将是不同的.有这个问题的解决方案吗?可能是每次强制某种算法的方法?或者这个评论在实践中是不是真的?毕竟,phase of the moon, or similar factors有点奇怪.
"月相依赖"的原因是它们省略了一些数据结构的初始化以挤出一点性能(当然,只有当它不影响解压缩的正确性时).压缩库不是一个不常见的技巧.因此,如果您将压缩代码放在一个单独的一次性过程中,并且您的操作系统将内存归零到一个进程(所有"大"操作系统都会执行,但某些较小的操作系统可能没有),那么您将始终获得相同的内容压缩结果.
另外,请注意以下内容,来自lzfP.h:
/*
* You may choose to pre-set the hash table (might be faster on some
* modern cpus and large (>>64k) blocks, and also makes compression
* deterministic/repeatable when the configuration otherwise is the same).
*/
#ifndef INIT_HTAB
# define INIT_HTAB 0
#endif
Run Code Online (Sandbox Code Playgroud)
所以我认为你只需要#define INIT_HTAB 1在编译libLZF时使其具有确定性,但如果没有进一步的分析就不会对它下注太多.