First, Introduction
Snappy (formerly known as Zippy) is Google's LZ77-based approach to fast data compression and decompression programs written in the C + + language and open source in 2011. Its target is not the maximum compression rate or compatibility with other compression programs, but rather a very high speed and reasonable compression ratio. Use a single core of the Core™ i7 processor running in 64-bit mode, compression speed of up to MB/s, decompression speed of up to MB/s. Compression rate is lower than gzip 20-100%
Snappy is widely used in Google projects, such as BigTable, MapReduce, and Google's internal RPC system for compressed data. It can be used in open source projects such as Cassandra, Hadoop, LevelDB, MongoDB, Rocksdb, and Lucene. [4] Decompression will detect if there is an error in the compressed stream. Snappy is not used in inline assembly and is portable.
Source: Wikipedia
Second, installation
1. Download: https://github.com/google/snappy.git
2, installation CMake
3. CD Snappy && mkdir build && CD build && cmake. /&& make && make install
Third, testing
#include <iostream>#include<string>#include<snappy.h>using namespacestd;intMainintargcChar*argv[]) { stringinput ="Hello World"; stringoutput; for(inti =0; I <5; i++) Input+=input; Snappy::compress (Input.data (), Input.size (),&output); cout<<"Input Size:"<< input.size () <<"Output Size:"<< output.size () <<Endl; stringoutput_uncom; Snappy::uncompress (Output.data (), Output.size (),&output_uncom); if(Input = =output_uncom) cout<<"same"<<Endl; Elsecout<<"Not same"<<Endl; return 0;}View Code
Compilation: g++ Test.cpp-o Test-lsnappy
Building Blocks: Snappy lossless compression algorithm