1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/snappy/src/snappy.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +// Copyright 2005 and onwards Google Inc. 1.5 +// 1.6 +// Redistribution and use in source and binary forms, with or without 1.7 +// modification, are permitted provided that the following conditions are 1.8 +// met: 1.9 +// 1.10 +// * Redistributions of source code must retain the above copyright 1.11 +// notice, this list of conditions and the following disclaimer. 1.12 +// * Redistributions in binary form must reproduce the above 1.13 +// copyright notice, this list of conditions and the following disclaimer 1.14 +// in the documentation and/or other materials provided with the 1.15 +// distribution. 1.16 +// * Neither the name of Google Inc. nor the names of its 1.17 +// contributors may be used to endorse or promote products derived from 1.18 +// this software without specific prior written permission. 1.19 +// 1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 +// 1.32 +// A light-weight compression algorithm. It is designed for speed of 1.33 +// compression and decompression, rather than for the utmost in space 1.34 +// savings. 1.35 +// 1.36 +// For getting better compression ratios when you are compressing data 1.37 +// with long repeated sequences or compressing data that is similar to 1.38 +// other data, while still compressing fast, you might look at first 1.39 +// using BMDiff and then compressing the output of BMDiff with 1.40 +// Snappy. 1.41 + 1.42 +#ifndef UTIL_SNAPPY_SNAPPY_H__ 1.43 +#define UTIL_SNAPPY_SNAPPY_H__ 1.44 + 1.45 +#include <stddef.h> 1.46 +#include <string> 1.47 + 1.48 +#include "snappy-stubs-public.h" 1.49 + 1.50 +namespace snappy { 1.51 + class Source; 1.52 + class Sink; 1.53 + 1.54 + // ------------------------------------------------------------------------ 1.55 + // Generic compression/decompression routines. 1.56 + // ------------------------------------------------------------------------ 1.57 + 1.58 + // Compress the bytes read from "*source" and append to "*sink". Return the 1.59 + // number of bytes written. 1.60 + size_t Compress(Source* source, Sink* sink); 1.61 + 1.62 + bool GetUncompressedLength(Source* source, uint32* result); 1.63 + 1.64 + // ------------------------------------------------------------------------ 1.65 + // Higher-level string based routines (should be sufficient for most users) 1.66 + // ------------------------------------------------------------------------ 1.67 + 1.68 + // Sets "*output" to the compressed version of "input[0,input_length-1]". 1.69 + // Original contents of *output are lost. 1.70 + // 1.71 + // REQUIRES: "input[]" is not an alias of "*output". 1.72 + size_t Compress(const char* input, size_t input_length, string* output); 1.73 + 1.74 + // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed". 1.75 + // Original contents of "*uncompressed" are lost. 1.76 + // 1.77 + // REQUIRES: "compressed[]" is not an alias of "*uncompressed". 1.78 + // 1.79 + // returns false if the message is corrupted and could not be decompressed 1.80 + bool Uncompress(const char* compressed, size_t compressed_length, 1.81 + string* uncompressed); 1.82 + 1.83 + 1.84 + // ------------------------------------------------------------------------ 1.85 + // Lower-level character array based routines. May be useful for 1.86 + // efficiency reasons in certain circumstances. 1.87 + // ------------------------------------------------------------------------ 1.88 + 1.89 + // REQUIRES: "compressed" must point to an area of memory that is at 1.90 + // least "MaxCompressedLength(input_length)" bytes in length. 1.91 + // 1.92 + // Takes the data stored in "input[0..input_length]" and stores 1.93 + // it in the array pointed to by "compressed". 1.94 + // 1.95 + // "*compressed_length" is set to the length of the compressed output. 1.96 + // 1.97 + // Example: 1.98 + // char* output = new char[snappy::MaxCompressedLength(input_length)]; 1.99 + // size_t output_length; 1.100 + // RawCompress(input, input_length, output, &output_length); 1.101 + // ... Process(output, output_length) ... 1.102 + // delete [] output; 1.103 + void RawCompress(const char* input, 1.104 + size_t input_length, 1.105 + char* compressed, 1.106 + size_t* compressed_length); 1.107 + 1.108 + // Given data in "compressed[0..compressed_length-1]" generated by 1.109 + // calling the Snappy::Compress routine, this routine 1.110 + // stores the uncompressed data to 1.111 + // uncompressed[0..GetUncompressedLength(compressed)-1] 1.112 + // returns false if the message is corrupted and could not be decrypted 1.113 + bool RawUncompress(const char* compressed, size_t compressed_length, 1.114 + char* uncompressed); 1.115 + 1.116 + // Given data from the byte source 'compressed' generated by calling 1.117 + // the Snappy::Compress routine, this routine stores the uncompressed 1.118 + // data to 1.119 + // uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1] 1.120 + // returns false if the message is corrupted and could not be decrypted 1.121 + bool RawUncompress(Source* compressed, char* uncompressed); 1.122 + 1.123 + // Returns the maximal size of the compressed representation of 1.124 + // input data that is "source_bytes" bytes in length; 1.125 + size_t MaxCompressedLength(size_t source_bytes); 1.126 + 1.127 + // REQUIRES: "compressed[]" was produced by RawCompress() or Compress() 1.128 + // Returns true and stores the length of the uncompressed data in 1.129 + // *result normally. Returns false on parsing error. 1.130 + // This operation takes O(1) time. 1.131 + bool GetUncompressedLength(const char* compressed, size_t compressed_length, 1.132 + size_t* result); 1.133 + 1.134 + // Returns true iff the contents of "compressed[]" can be uncompressed 1.135 + // successfully. Does not return the uncompressed data. Takes 1.136 + // time proportional to compressed_length, but is usually at least 1.137 + // a factor of four faster than actual decompression. 1.138 + bool IsValidCompressedBuffer(const char* compressed, 1.139 + size_t compressed_length); 1.140 + 1.141 + // *** DO NOT CHANGE THE VALUE OF kBlockSize *** 1.142 + // 1.143 + // New Compression code chops up the input into blocks of at most 1.144 + // the following size. This ensures that back-references in the 1.145 + // output never cross kBlockSize block boundaries. This can be 1.146 + // helpful in implementing blocked decompression. However the 1.147 + // decompression code should not rely on this guarantee since older 1.148 + // compression code may not obey it. 1.149 + static const int kBlockLog = 15; 1.150 + static const size_t kBlockSize = 1 << kBlockLog; 1.151 + 1.152 + static const int kMaxHashTableBits = 14; 1.153 + static const size_t kMaxHashTableSize = 1 << kMaxHashTableBits; 1.154 + 1.155 +} // end namespace snappy 1.156 + 1.157 + 1.158 +#endif // UTIL_SNAPPY_SNAPPY_H__