diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-04-10 11:34:11 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-04-10 11:44:44 +0300 |
commit | ce49046255d74900ee2f807a2c421f52c50ee7f1 (patch) | |
tree | 49995017ad6c2248311d4e65af14b3f9e66066bf /contrib/libs/snappy/snappy.h | |
parent | 908385834c122b8d44d0fdf2372b2445b86705e1 (diff) | |
download | ydb-ce49046255d74900ee2f807a2c421f52c50ee7f1.tar.gz |
Update contrib/libs/snappy to 1.2.0
eb017c6cebd9382319a1c949f016369420906729
Diffstat (limited to 'contrib/libs/snappy/snappy.h')
-rw-r--r-- | contrib/libs/snappy/snappy.h | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/contrib/libs/snappy/snappy.h b/contrib/libs/snappy/snappy.h index 3fe79b0b58..0ad7bd6b9b 100644 --- a/contrib/libs/snappy/snappy.h +++ b/contrib/libs/snappy/snappy.h @@ -51,13 +51,36 @@ namespace snappy { class Source; class Sink; + struct CompressionOptions { + // Compression level. + // Level 1 is the fastest + // Level 2 is a little slower but provides better compression. Level 2 is + // **EXPERIMENTAL** for the time being. It might happen that we decide to + // fall back to level 1 in the future. + // Levels 3+ are currently not supported. We plan to support levels up to + // 9 in the future. + // If you played with other compression algorithms, level 1 is equivalent to + // fast mode (level 1) of LZ4, level 2 is equivalent to LZ4's level 2 mode + // and compresses somewhere around zstd:-3 and zstd:-2 but generally with + // faster decompression speeds than snappy:1 and zstd:-3. + int level = DefaultCompressionLevel(); + + constexpr CompressionOptions() = default; + constexpr CompressionOptions(int compression_level) + : level(compression_level) {} + static constexpr int MinCompressionLevel() { return 1; } + static constexpr int MaxCompressionLevel() { return 2; } + static constexpr int DefaultCompressionLevel() { return 1; } + }; + // ------------------------------------------------------------------------ // Generic compression/decompression routines. // ------------------------------------------------------------------------ - // Compress the bytes read from "*source" and append to "*sink". Return the + // Compress the bytes read from "*reader" and append to "*writer". Return the // number of bytes written. - size_t Compress(Source* source, Sink* sink); + size_t Compress(Source* reader, Sink* writer, + CompressionOptions options = {}); // Find the uncompressed length of the given stream, as given by the header. // Note that the true length could deviate from this; the stream could e.g. @@ -77,16 +100,17 @@ namespace snappy { // // REQUIRES: "input[]" is not an alias of "*compressed". size_t Compress(const char* input, size_t input_length, - std::string* compressed); + std::string* compressed, CompressionOptions options = {}); size_t Compress(const char* input, size_t input_length, - TString* compressed); + TString* compressed, CompressionOptions options = {}); // Same as `Compress` above but taking an `iovec` array as input. Note that // this function preprocesses the inputs to compute the sum of // `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use // `RawCompressFromIOVec` below. size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt, - std::string* compressed); + std::string* compressed, + CompressionOptions options = {}); // Decompresses "compressed[0..compressed_length-1]" to "*uncompressed". // Original contents of "*uncompressed" are lost. @@ -131,16 +155,15 @@ namespace snappy { // RawCompress(input, input_length, output, &output_length); // ... Process(output, output_length) ... // delete [] output; - void RawCompress(const char* input, - size_t input_length, - char* compressed, - size_t* compressed_length); + void RawCompress(const char* input, size_t input_length, char* compressed, + size_t* compressed_length, CompressionOptions options = {}); // Same as `RawCompress` above but taking an `iovec` array as input. Note that // `uncompressed_length` is the total number of bytes to be read from the // elements of `iov` (_not_ the number of elements in `iov`). void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length, - char* compressed, size_t* compressed_length); + char* compressed, size_t* compressed_length, + CompressionOptions options = {}); // Given data in "compressed[0..compressed_length-1]" generated by // calling the Snappy::Compress routine, this routine @@ -220,7 +243,7 @@ namespace snappy { static constexpr int kMinHashTableBits = 8; static constexpr size_t kMinHashTableSize = 1 << kMinHashTableBits; - static constexpr int kMaxHashTableBits = 14; + static constexpr int kMaxHashTableBits = 15; static constexpr size_t kMaxHashTableSize = 1 << kMaxHashTableBits; } // end namespace snappy |