Building blocks: Snappy lossless compression algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.