高性能的数据压缩库libzling

  libzling(https://github.com/richox/libzling)是一款高性能的数据压缩库,在压缩时间和压缩率上都超过了流行的zlib/gzip。libzling使用的是ROLZ字典算法和Polar编码,这两个算法的说明可以参考这两篇文章:http://www.cnblogs.com/richselian/archive/2012/11/10/2764427.htmlhttp://www.cnblogs.com/richselian/archive/2012/11/09/2763162.html

  libzling使用的是1阶ROLZ字典编码和0阶Polar编码,在权威的 Large Text Compression Benchmark 测评上,压缩时间、解压时间和压缩率都分别超过gzip约50%、20%、10%左右。libzling最适用于一般的文本数据,对大量冗余的文本日志数据性能更佳,压缩率可以压缩gzip的30%以上。

 

  使用libzling的方式很简单,首先从github上clone最新的版本:

git clone https://github.com/richox/libzling

  然后cd到build目录下,使用cmake编译(cmake的具体安装方法可以Google):

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
make
make install

 

  以下是最简单的使用libzling的方式,具体的接口文档现在还没有完成,可以参考源代码中的demo程序:./sample/zling.cpp

  代码可以使用g++编译,编译选项加上-lzling即可。

 1 #include "libzling.h"
 2 
 3 int main() {
 4     // compress
 5     {
 6         FILE* fin = fopen("./1.txt", "rb");
 7         FILE* fout = fopen("./1.txt.zlng", "wb");
 8 
 9         baidu::zling::FileInputer  inputer(fin);
10         baidu::zling::FileOutputer outputer(fout);
11 
12         baidu::zling::Encode(&inputer, &outputer);
13         fclose(fin);
14         fclose(fout);
15     }
16 
17     // decompress
18     {
19         FILE* fin = fopen("./1.txt.zlng", "rb");
20         FILE* fout = fopen("./2.txt", "wb");
21 
22         baidu::zling::FileInputer  inputer(fin);
23         baidu::zling::FileOutputer outputer(fout);
24 
25         baidu::zling::Decode(&inputer, &outputer);
26         fclose(fin);
27         fclose(fout);
28     }
29     return 0;
30 }

 

转载于:https://www.cnblogs.com/richselian/p/3538466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值