zoukankan      html  css  js  c++  java
  • 高性能的数据压缩库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 }
  • 相关阅读:
    php 异步执行脚本
    微信扫描带参数二维码事件
    windows7搭建wnmp环境
    Windows下安装Redis及php的redis拓展教程
    英语翻译(一维map)
    转圈游戏
    蓝桥杯剪邮票
    再谈组合
    关于inf设置为0x3f3f3f3f
    枚举排列组合(dfs)
  • 原文地址:https://www.cnblogs.com/richselian/p/3538466.html
Copyright © 2011-2022 走看看