@nxtedition/rocksdb 5.2.39 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.cc +68 -34
- package/deps/rocksdb/rocksdb.gyp +34 -10
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/{prebuilds/linux-x64 → linux-arm64}/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/deps/snappy/freebsd/config.h +0 -135
- package/deps/snappy/freebsd/snappy-stubs-public.h +0 -100
- package/deps/snappy/linux/config.h +0 -135
- package/deps/snappy/linux/snappy-stubs-public.h +0 -100
- package/deps/snappy/mac/config.h +0 -137
- package/deps/snappy/mac/snappy-stubs-public.h +0 -100
- package/deps/snappy/openbsd/config.h +0 -135
- package/deps/snappy/openbsd/snappy-stubs-public.h +0 -100
- package/deps/snappy/snappy-1.1.7/COPYING +0 -54
- package/deps/snappy/snappy-1.1.7/README.md +0 -149
- package/deps/snappy/snappy-1.1.7/cmake/SnappyConfig.cmake +0 -1
- package/deps/snappy/snappy-1.1.7/cmake/config.h.in +0 -62
- package/deps/snappy/snappy-1.1.7/snappy-c.cc +0 -90
- package/deps/snappy/snappy-1.1.7/snappy-c.h +0 -138
- package/deps/snappy/snappy-1.1.7/snappy-internal.h +0 -224
- package/deps/snappy/snappy-1.1.7/snappy-sinksource.cc +0 -104
- package/deps/snappy/snappy-1.1.7/snappy-sinksource.h +0 -182
- package/deps/snappy/snappy-1.1.7/snappy-stubs-internal.cc +0 -42
- package/deps/snappy/snappy-1.1.7/snappy-stubs-internal.h +0 -561
- package/deps/snappy/snappy-1.1.7/snappy-stubs-public.h.in +0 -94
- package/deps/snappy/snappy-1.1.7/snappy-test.cc +0 -612
- package/deps/snappy/snappy-1.1.7/snappy-test.h +0 -573
- package/deps/snappy/snappy-1.1.7/snappy.cc +0 -1515
- package/deps/snappy/snappy-1.1.7/snappy.h +0 -203
- package/deps/snappy/snappy-1.1.7/snappy_unittest.cc +0 -1410
- package/deps/snappy/snappy.gyp +0 -93
- package/deps/snappy/solaris/config.h +0 -135
- package/deps/snappy/solaris/snappy-stubs-public.h +0 -100
- package/deps/snappy/win32/config.h +0 -29
- package/deps/snappy/win32/snappy-stubs-public.h +0 -100
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
Snappy, a fast compressor/decompressor.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Introduction
|
|
5
|
-
============
|
|
6
|
-
|
|
7
|
-
Snappy is a compression/decompression library. It does not aim for maximum
|
|
8
|
-
compression, or compatibility with any other compression library; instead,
|
|
9
|
-
it aims for very high speeds and reasonable compression. For instance,
|
|
10
|
-
compared to the fastest mode of zlib, Snappy is an order of magnitude faster
|
|
11
|
-
for most inputs, but the resulting compressed files are anywhere from 20% to
|
|
12
|
-
100% bigger. (For more information, see "Performance", below.)
|
|
13
|
-
|
|
14
|
-
Snappy has the following properties:
|
|
15
|
-
|
|
16
|
-
* Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code.
|
|
17
|
-
See "Performance" below.
|
|
18
|
-
* Stable: Over the last few years, Snappy has compressed and decompressed
|
|
19
|
-
petabytes of data in Google's production environment. The Snappy bitstream
|
|
20
|
-
format is stable and will not change between versions.
|
|
21
|
-
* Robust: The Snappy decompressor is designed not to crash in the face of
|
|
22
|
-
corrupted or malicious input.
|
|
23
|
-
* Free and open source software: Snappy is licensed under a BSD-type license.
|
|
24
|
-
For more information, see the included COPYING file.
|
|
25
|
-
|
|
26
|
-
Snappy has previously been called "Zippy" in some Google presentations
|
|
27
|
-
and the like.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Performance
|
|
31
|
-
===========
|
|
32
|
-
|
|
33
|
-
Snappy is intended to be fast. On a single core of a Core i7 processor
|
|
34
|
-
in 64-bit mode, it compresses at about 250 MB/sec or more and decompresses at
|
|
35
|
-
about 500 MB/sec or more. (These numbers are for the slowest inputs in our
|
|
36
|
-
benchmark suite; others are much faster.) In our tests, Snappy usually
|
|
37
|
-
is faster than algorithms in the same class (e.g. LZO, LZF, QuickLZ,
|
|
38
|
-
etc.) while achieving comparable compression ratios.
|
|
39
|
-
|
|
40
|
-
Typical compression ratios (based on the benchmark suite) are about 1.5-1.7x
|
|
41
|
-
for plain text, about 2-4x for HTML, and of course 1.0x for JPEGs, PNGs and
|
|
42
|
-
other already-compressed data. Similar numbers for zlib in its fastest mode
|
|
43
|
-
are 2.6-2.8x, 3-7x and 1.0x, respectively. More sophisticated algorithms are
|
|
44
|
-
capable of achieving yet higher compression rates, although usually at the
|
|
45
|
-
expense of speed. Of course, compression ratio will vary significantly with
|
|
46
|
-
the input.
|
|
47
|
-
|
|
48
|
-
Although Snappy should be fairly portable, it is primarily optimized
|
|
49
|
-
for 64-bit x86-compatible processors, and may run slower in other environments.
|
|
50
|
-
In particular:
|
|
51
|
-
|
|
52
|
-
- Snappy uses 64-bit operations in several places to process more data at
|
|
53
|
-
once than would otherwise be possible.
|
|
54
|
-
- Snappy assumes unaligned 32- and 64-bit loads and stores are cheap.
|
|
55
|
-
On some platforms, these must be emulated with single-byte loads
|
|
56
|
-
and stores, which is much slower.
|
|
57
|
-
- Snappy assumes little-endian throughout, and needs to byte-swap data in
|
|
58
|
-
several places if running on a big-endian platform.
|
|
59
|
-
|
|
60
|
-
Experience has shown that even heavily tuned code can be improved.
|
|
61
|
-
Performance optimizations, whether for 64-bit x86 or other platforms,
|
|
62
|
-
are of course most welcome; see "Contact", below.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Building
|
|
66
|
-
========
|
|
67
|
-
|
|
68
|
-
CMake is supported and autotools will soon be deprecated.
|
|
69
|
-
You need CMake 3.4 or above to build:
|
|
70
|
-
|
|
71
|
-
mkdir build
|
|
72
|
-
cd build && cmake ../ && make
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Usage
|
|
76
|
-
=====
|
|
77
|
-
|
|
78
|
-
Note that Snappy, both the implementation and the main interface,
|
|
79
|
-
is written in C++. However, several third-party bindings to other languages
|
|
80
|
-
are available; see the home page at http://google.github.io/snappy/
|
|
81
|
-
for more information. Also, if you want to use Snappy from C code, you can
|
|
82
|
-
use the included C bindings in snappy-c.h.
|
|
83
|
-
|
|
84
|
-
To use Snappy from your own C++ program, include the file "snappy.h" from
|
|
85
|
-
your calling file, and link against the compiled library.
|
|
86
|
-
|
|
87
|
-
There are many ways to call Snappy, but the simplest possible is
|
|
88
|
-
|
|
89
|
-
snappy::Compress(input.data(), input.size(), &output);
|
|
90
|
-
|
|
91
|
-
and similarly
|
|
92
|
-
|
|
93
|
-
snappy::Uncompress(input.data(), input.size(), &output);
|
|
94
|
-
|
|
95
|
-
where "input" and "output" are both instances of std::string.
|
|
96
|
-
|
|
97
|
-
There are other interfaces that are more flexible in various ways, including
|
|
98
|
-
support for custom (non-array) input sources. See the header file for more
|
|
99
|
-
information.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
Tests and benchmarks
|
|
103
|
-
====================
|
|
104
|
-
|
|
105
|
-
When you compile Snappy, snappy_unittest is compiled in addition to the
|
|
106
|
-
library itself. You do not need it to use the compressor from your own library,
|
|
107
|
-
but it contains several useful components for Snappy development.
|
|
108
|
-
|
|
109
|
-
First of all, it contains unit tests, verifying correctness on your machine in
|
|
110
|
-
various scenarios. If you want to change or optimize Snappy, please run the
|
|
111
|
-
tests to verify you have not broken anything. Note that if you have the
|
|
112
|
-
Google Test library installed, unit test behavior (especially failures) will be
|
|
113
|
-
significantly more user-friendly. You can find Google Test at
|
|
114
|
-
|
|
115
|
-
http://github.com/google/googletest
|
|
116
|
-
|
|
117
|
-
You probably also want the gflags library for handling of command-line flags;
|
|
118
|
-
you can find it at
|
|
119
|
-
|
|
120
|
-
http://gflags.github.io/gflags/
|
|
121
|
-
|
|
122
|
-
In addition to the unit tests, snappy contains microbenchmarks used to
|
|
123
|
-
tune compression and decompression performance. These are automatically run
|
|
124
|
-
before the unit tests, but you can disable them using the flag
|
|
125
|
-
--run_microbenchmarks=false if you have gflags installed (otherwise you will
|
|
126
|
-
need to edit the source).
|
|
127
|
-
|
|
128
|
-
Finally, snappy can benchmark Snappy against a few other compression libraries
|
|
129
|
-
(zlib, LZO, LZF, and QuickLZ), if they were detected at configure time.
|
|
130
|
-
To benchmark using a given file, give the compression algorithm you want to test
|
|
131
|
-
Snappy against (e.g. --zlib) and then a list of one or more file names on the
|
|
132
|
-
command line. The testdata/ directory contains the files used by the
|
|
133
|
-
microbenchmark, which should provide a reasonably balanced starting point for
|
|
134
|
-
benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they
|
|
135
|
-
are used to verify correctness in the presence of corrupted data in the unit
|
|
136
|
-
test.)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
Contact
|
|
140
|
-
=======
|
|
141
|
-
|
|
142
|
-
Snappy is distributed through GitHub. For the latest version, a bug tracker,
|
|
143
|
-
and other information, see
|
|
144
|
-
|
|
145
|
-
http://google.github.io/snappy/
|
|
146
|
-
|
|
147
|
-
or the repository at
|
|
148
|
-
|
|
149
|
-
https://github.com/google/snappy
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
include("${CMAKE_CURRENT_LIST_DIR}/SnappyTargets.cmake")
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
|
2
|
-
#define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
|
3
|
-
|
|
4
|
-
/* Define to 1 if the compiler supports __builtin_ctz and friends. */
|
|
5
|
-
#cmakedefine HAVE_BUILTIN_CTZ 1
|
|
6
|
-
|
|
7
|
-
/* Define to 1 if the compiler supports __builtin_expect. */
|
|
8
|
-
#cmakedefine HAVE_BUILTIN_EXPECT 1
|
|
9
|
-
|
|
10
|
-
/* Define to 1 if you have the <byteswap.h> header file. */
|
|
11
|
-
#cmakedefine HAVE_BYTESWAP_H 1
|
|
12
|
-
|
|
13
|
-
/* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */
|
|
14
|
-
#cmakedefine HAVE_FUNC_MMAP 1
|
|
15
|
-
|
|
16
|
-
/* Define to 1 if you have a definition for sysconf() in <unistd.h>. */
|
|
17
|
-
#cmakedefine HAVE_FUNC_SYSCONF 1
|
|
18
|
-
|
|
19
|
-
/* Define to 1 to use the gflags package for command-line parsing. */
|
|
20
|
-
#cmakedefine HAVE_GFLAGS 1
|
|
21
|
-
|
|
22
|
-
/* Define to 1 if you have Google Test. */
|
|
23
|
-
#cmakedefine HAVE_GTEST 1
|
|
24
|
-
|
|
25
|
-
/* Define to 1 if you have the `lzo2' library (-llzo2). */
|
|
26
|
-
#cmakedefine HAVE_LIBLZO2 1
|
|
27
|
-
|
|
28
|
-
/* Define to 1 if you have the `z' library (-lz). */
|
|
29
|
-
#cmakedefine HAVE_LIBZ 1
|
|
30
|
-
|
|
31
|
-
/* Define to 1 if you have the <stddef.h> header file. */
|
|
32
|
-
#cmakedefine HAVE_STDDEF_H 1
|
|
33
|
-
|
|
34
|
-
/* Define to 1 if you have the <stdint.h> header file. */
|
|
35
|
-
#cmakedefine HAVE_STDINT_H 1
|
|
36
|
-
|
|
37
|
-
/* Define to 1 if you have the <sys/endian.h> header file. */
|
|
38
|
-
#cmakedefine HAVE_SYS_ENDIAN_H 1
|
|
39
|
-
|
|
40
|
-
/* Define to 1 if you have the <sys/mman.h> header file. */
|
|
41
|
-
#cmakedefine HAVE_SYS_MMAN_H 1
|
|
42
|
-
|
|
43
|
-
/* Define to 1 if you have the <sys/resource.h> header file. */
|
|
44
|
-
#cmakedefine HAVE_SYS_RESOURCE_H 1
|
|
45
|
-
|
|
46
|
-
/* Define to 1 if you have the <sys/time.h> header file. */
|
|
47
|
-
#cmakedefine HAVE_SYS_TIME_H 1
|
|
48
|
-
|
|
49
|
-
/* Define to 1 if you have the <sys/uio.h> header file. */
|
|
50
|
-
#cmakedefine HAVE_SYS_UIO_H 1
|
|
51
|
-
|
|
52
|
-
/* Define to 1 if you have the <unistd.h> header file. */
|
|
53
|
-
#cmakedefine HAVE_UNISTD_H 1
|
|
54
|
-
|
|
55
|
-
/* Define to 1 if you have the <windows.h> header file. */
|
|
56
|
-
#cmakedefine HAVE_WINDOWS_H 1
|
|
57
|
-
|
|
58
|
-
/* Define to 1 if your processor stores words with the most significant byte
|
|
59
|
-
first (like Motorola and SPARC, unlike Intel and VAX). */
|
|
60
|
-
#cmakedefine SNAPPY_IS_BIG_ENDIAN 1
|
|
61
|
-
|
|
62
|
-
#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.
|
|
2
|
-
//
|
|
3
|
-
// Redistribution and use in source and binary forms, with or without
|
|
4
|
-
// modification, are permitted provided that the following conditions are
|
|
5
|
-
// met:
|
|
6
|
-
//
|
|
7
|
-
// * Redistributions of source code must retain the above copyright
|
|
8
|
-
// notice, this list of conditions and the following disclaimer.
|
|
9
|
-
// * Redistributions in binary form must reproduce the above
|
|
10
|
-
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
-
// in the documentation and/or other materials provided with the
|
|
12
|
-
// distribution.
|
|
13
|
-
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
-
// contributors may be used to endorse or promote products derived from
|
|
15
|
-
// this software without specific prior written permission.
|
|
16
|
-
//
|
|
17
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
-
|
|
29
|
-
#include "snappy.h"
|
|
30
|
-
#include "snappy-c.h"
|
|
31
|
-
|
|
32
|
-
extern "C" {
|
|
33
|
-
|
|
34
|
-
snappy_status snappy_compress(const char* input,
|
|
35
|
-
size_t input_length,
|
|
36
|
-
char* compressed,
|
|
37
|
-
size_t *compressed_length) {
|
|
38
|
-
if (*compressed_length < snappy_max_compressed_length(input_length)) {
|
|
39
|
-
return SNAPPY_BUFFER_TOO_SMALL;
|
|
40
|
-
}
|
|
41
|
-
snappy::RawCompress(input, input_length, compressed, compressed_length);
|
|
42
|
-
return SNAPPY_OK;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
snappy_status snappy_uncompress(const char* compressed,
|
|
46
|
-
size_t compressed_length,
|
|
47
|
-
char* uncompressed,
|
|
48
|
-
size_t* uncompressed_length) {
|
|
49
|
-
size_t real_uncompressed_length;
|
|
50
|
-
if (!snappy::GetUncompressedLength(compressed,
|
|
51
|
-
compressed_length,
|
|
52
|
-
&real_uncompressed_length)) {
|
|
53
|
-
return SNAPPY_INVALID_INPUT;
|
|
54
|
-
}
|
|
55
|
-
if (*uncompressed_length < real_uncompressed_length) {
|
|
56
|
-
return SNAPPY_BUFFER_TOO_SMALL;
|
|
57
|
-
}
|
|
58
|
-
if (!snappy::RawUncompress(compressed, compressed_length, uncompressed)) {
|
|
59
|
-
return SNAPPY_INVALID_INPUT;
|
|
60
|
-
}
|
|
61
|
-
*uncompressed_length = real_uncompressed_length;
|
|
62
|
-
return SNAPPY_OK;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
size_t snappy_max_compressed_length(size_t source_length) {
|
|
66
|
-
return snappy::MaxCompressedLength(source_length);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
snappy_status snappy_uncompressed_length(const char *compressed,
|
|
70
|
-
size_t compressed_length,
|
|
71
|
-
size_t *result) {
|
|
72
|
-
if (snappy::GetUncompressedLength(compressed,
|
|
73
|
-
compressed_length,
|
|
74
|
-
result)) {
|
|
75
|
-
return SNAPPY_OK;
|
|
76
|
-
} else {
|
|
77
|
-
return SNAPPY_INVALID_INPUT;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
snappy_status snappy_validate_compressed_buffer(const char *compressed,
|
|
82
|
-
size_t compressed_length) {
|
|
83
|
-
if (snappy::IsValidCompressedBuffer(compressed, compressed_length)) {
|
|
84
|
-
return SNAPPY_OK;
|
|
85
|
-
} else {
|
|
86
|
-
return SNAPPY_INVALID_INPUT;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
} // extern "C"
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.
|
|
3
|
-
*
|
|
4
|
-
* Redistribution and use in source and binary forms, with or without
|
|
5
|
-
* modification, are permitted provided that the following conditions are
|
|
6
|
-
* met:
|
|
7
|
-
*
|
|
8
|
-
* * Redistributions of source code must retain the above copyright
|
|
9
|
-
* notice, this list of conditions and the following disclaimer.
|
|
10
|
-
* * Redistributions in binary form must reproduce the above
|
|
11
|
-
* copyright notice, this list of conditions and the following disclaimer
|
|
12
|
-
* in the documentation and/or other materials provided with the
|
|
13
|
-
* distribution.
|
|
14
|
-
* * Neither the name of Google Inc. nor the names of its
|
|
15
|
-
* contributors may be used to endorse or promote products derived from
|
|
16
|
-
* this software without specific prior written permission.
|
|
17
|
-
*
|
|
18
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
|
-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
-
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
|
-
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23
|
-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
24
|
-
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25
|
-
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
26
|
-
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
*
|
|
30
|
-
* Plain C interface (a wrapper around the C++ implementation).
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_
|
|
34
|
-
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_
|
|
35
|
-
|
|
36
|
-
#ifdef __cplusplus
|
|
37
|
-
extern "C" {
|
|
38
|
-
#endif
|
|
39
|
-
|
|
40
|
-
#include <stddef.h>
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
* Return values; see the documentation for each function to know
|
|
44
|
-
* what each can return.
|
|
45
|
-
*/
|
|
46
|
-
typedef enum {
|
|
47
|
-
SNAPPY_OK = 0,
|
|
48
|
-
SNAPPY_INVALID_INPUT = 1,
|
|
49
|
-
SNAPPY_BUFFER_TOO_SMALL = 2
|
|
50
|
-
} snappy_status;
|
|
51
|
-
|
|
52
|
-
/*
|
|
53
|
-
* Takes the data stored in "input[0..input_length-1]" and stores
|
|
54
|
-
* it in the array pointed to by "compressed".
|
|
55
|
-
*
|
|
56
|
-
* <compressed_length> signals the space available in "compressed".
|
|
57
|
-
* If it is not at least equal to "snappy_max_compressed_length(input_length)",
|
|
58
|
-
* SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
|
|
59
|
-
* <compressed_length> contains the true length of the compressed output,
|
|
60
|
-
* and SNAPPY_OK is returned.
|
|
61
|
-
*
|
|
62
|
-
* Example:
|
|
63
|
-
* size_t output_length = snappy_max_compressed_length(input_length);
|
|
64
|
-
* char* output = (char*)malloc(output_length);
|
|
65
|
-
* if (snappy_compress(input, input_length, output, &output_length)
|
|
66
|
-
* == SNAPPY_OK) {
|
|
67
|
-
* ... Process(output, output_length) ...
|
|
68
|
-
* }
|
|
69
|
-
* free(output);
|
|
70
|
-
*/
|
|
71
|
-
snappy_status snappy_compress(const char* input,
|
|
72
|
-
size_t input_length,
|
|
73
|
-
char* compressed,
|
|
74
|
-
size_t* compressed_length);
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
* Given data in "compressed[0..compressed_length-1]" generated by
|
|
78
|
-
* calling the snappy_compress routine, this routine stores
|
|
79
|
-
* the uncompressed data to
|
|
80
|
-
* uncompressed[0..uncompressed_length-1].
|
|
81
|
-
* Returns failure (a value not equal to SNAPPY_OK) if the message
|
|
82
|
-
* is corrupted and could not be decrypted.
|
|
83
|
-
*
|
|
84
|
-
* <uncompressed_length> signals the space available in "uncompressed".
|
|
85
|
-
* If it is not at least equal to the value returned by
|
|
86
|
-
* snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL
|
|
87
|
-
* is returned. After successful decompression, <uncompressed_length>
|
|
88
|
-
* contains the true length of the decompressed output.
|
|
89
|
-
*
|
|
90
|
-
* Example:
|
|
91
|
-
* size_t output_length;
|
|
92
|
-
* if (snappy_uncompressed_length(input, input_length, &output_length)
|
|
93
|
-
* != SNAPPY_OK) {
|
|
94
|
-
* ... fail ...
|
|
95
|
-
* }
|
|
96
|
-
* char* output = (char*)malloc(output_length);
|
|
97
|
-
* if (snappy_uncompress(input, input_length, output, &output_length)
|
|
98
|
-
* == SNAPPY_OK) {
|
|
99
|
-
* ... Process(output, output_length) ...
|
|
100
|
-
* }
|
|
101
|
-
* free(output);
|
|
102
|
-
*/
|
|
103
|
-
snappy_status snappy_uncompress(const char* compressed,
|
|
104
|
-
size_t compressed_length,
|
|
105
|
-
char* uncompressed,
|
|
106
|
-
size_t* uncompressed_length);
|
|
107
|
-
|
|
108
|
-
/*
|
|
109
|
-
* Returns the maximal size of the compressed representation of
|
|
110
|
-
* input data that is "source_length" bytes in length.
|
|
111
|
-
*/
|
|
112
|
-
size_t snappy_max_compressed_length(size_t source_length);
|
|
113
|
-
|
|
114
|
-
/*
|
|
115
|
-
* REQUIRES: "compressed[]" was produced by snappy_compress()
|
|
116
|
-
* Returns SNAPPY_OK and stores the length of the uncompressed data in
|
|
117
|
-
* *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.
|
|
118
|
-
* This operation takes O(1) time.
|
|
119
|
-
*/
|
|
120
|
-
snappy_status snappy_uncompressed_length(const char* compressed,
|
|
121
|
-
size_t compressed_length,
|
|
122
|
-
size_t* result);
|
|
123
|
-
|
|
124
|
-
/*
|
|
125
|
-
* Check if the contents of "compressed[]" can be uncompressed successfully.
|
|
126
|
-
* Does not return the uncompressed data; if so, returns SNAPPY_OK,
|
|
127
|
-
* or if not, returns SNAPPY_INVALID_INPUT.
|
|
128
|
-
* Takes time proportional to compressed_length, but is usually at least a
|
|
129
|
-
* factor of four faster than actual decompression.
|
|
130
|
-
*/
|
|
131
|
-
snappy_status snappy_validate_compressed_buffer(const char* compressed,
|
|
132
|
-
size_t compressed_length);
|
|
133
|
-
|
|
134
|
-
#ifdef __cplusplus
|
|
135
|
-
} // extern "C"
|
|
136
|
-
#endif
|
|
137
|
-
|
|
138
|
-
#endif /* THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
// Copyright 2008 Google Inc. All Rights Reserved.
|
|
2
|
-
//
|
|
3
|
-
// Redistribution and use in source and binary forms, with or without
|
|
4
|
-
// modification, are permitted provided that the following conditions are
|
|
5
|
-
// met:
|
|
6
|
-
//
|
|
7
|
-
// * Redistributions of source code must retain the above copyright
|
|
8
|
-
// notice, this list of conditions and the following disclaimer.
|
|
9
|
-
// * Redistributions in binary form must reproduce the above
|
|
10
|
-
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
-
// in the documentation and/or other materials provided with the
|
|
12
|
-
// distribution.
|
|
13
|
-
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
-
// contributors may be used to endorse or promote products derived from
|
|
15
|
-
// this software without specific prior written permission.
|
|
16
|
-
//
|
|
17
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
-
//
|
|
29
|
-
// Internals shared between the Snappy implementation and its unittest.
|
|
30
|
-
|
|
31
|
-
#ifndef THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_
|
|
32
|
-
#define THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_
|
|
33
|
-
|
|
34
|
-
#include "snappy-stubs-internal.h"
|
|
35
|
-
|
|
36
|
-
namespace snappy {
|
|
37
|
-
namespace internal {
|
|
38
|
-
|
|
39
|
-
class WorkingMemory {
|
|
40
|
-
public:
|
|
41
|
-
WorkingMemory() : large_table_(NULL) { }
|
|
42
|
-
~WorkingMemory() { delete[] large_table_; }
|
|
43
|
-
|
|
44
|
-
// Allocates and clears a hash table using memory in "*this",
|
|
45
|
-
// stores the number of buckets in "*table_size" and returns a pointer to
|
|
46
|
-
// the base of the hash table.
|
|
47
|
-
uint16* GetHashTable(size_t input_size, int* table_size);
|
|
48
|
-
|
|
49
|
-
private:
|
|
50
|
-
uint16 small_table_[1<<10]; // 2KB
|
|
51
|
-
uint16* large_table_; // Allocated only when needed
|
|
52
|
-
|
|
53
|
-
// No copying
|
|
54
|
-
WorkingMemory(const WorkingMemory&);
|
|
55
|
-
void operator=(const WorkingMemory&);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Flat array compression that does not emit the "uncompressed length"
|
|
59
|
-
// prefix. Compresses "input" string to the "*op" buffer.
|
|
60
|
-
//
|
|
61
|
-
// REQUIRES: "input_length <= kBlockSize"
|
|
62
|
-
// REQUIRES: "op" points to an array of memory that is at least
|
|
63
|
-
// "MaxCompressedLength(input_length)" in size.
|
|
64
|
-
// REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
|
|
65
|
-
// REQUIRES: "table_size" is a power of two
|
|
66
|
-
//
|
|
67
|
-
// Returns an "end" pointer into "op" buffer.
|
|
68
|
-
// "end - op" is the compressed size of "input".
|
|
69
|
-
char* CompressFragment(const char* input,
|
|
70
|
-
size_t input_length,
|
|
71
|
-
char* op,
|
|
72
|
-
uint16* table,
|
|
73
|
-
const int table_size);
|
|
74
|
-
|
|
75
|
-
// Find the largest n such that
|
|
76
|
-
//
|
|
77
|
-
// s1[0,n-1] == s2[0,n-1]
|
|
78
|
-
// and n <= (s2_limit - s2).
|
|
79
|
-
//
|
|
80
|
-
// Return make_pair(n, n < 8).
|
|
81
|
-
// Does not read *s2_limit or beyond.
|
|
82
|
-
// Does not read *(s1 + (s2_limit - s2)) or beyond.
|
|
83
|
-
// Requires that s2_limit >= s2.
|
|
84
|
-
//
|
|
85
|
-
// Separate implementation for 64-bit, little-endian cpus.
|
|
86
|
-
#if !defined(SNAPPY_IS_BIG_ENDIAN) && \
|
|
87
|
-
(defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM))
|
|
88
|
-
static inline std::pair<size_t, bool> FindMatchLength(const char* s1,
|
|
89
|
-
const char* s2,
|
|
90
|
-
const char* s2_limit) {
|
|
91
|
-
assert(s2_limit >= s2);
|
|
92
|
-
size_t matched = 0;
|
|
93
|
-
|
|
94
|
-
// This block isn't necessary for correctness; we could just start looping
|
|
95
|
-
// immediately. As an optimization though, it is useful. It creates some not
|
|
96
|
-
// uncommon code paths that determine, without extra effort, whether the match
|
|
97
|
-
// length is less than 8. In short, we are hoping to avoid a conditional
|
|
98
|
-
// branch, and perhaps get better code layout from the C++ compiler.
|
|
99
|
-
if (SNAPPY_PREDICT_TRUE(s2 <= s2_limit - 8)) {
|
|
100
|
-
uint64 a1 = UNALIGNED_LOAD64(s1);
|
|
101
|
-
uint64 a2 = UNALIGNED_LOAD64(s2);
|
|
102
|
-
if (a1 != a2) {
|
|
103
|
-
return std::pair<size_t, bool>(Bits::FindLSBSetNonZero64(a1 ^ a2) >> 3,
|
|
104
|
-
true);
|
|
105
|
-
} else {
|
|
106
|
-
matched = 8;
|
|
107
|
-
s2 += 8;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Find out how long the match is. We loop over the data 64 bits at a
|
|
112
|
-
// time until we find a 64-bit block that doesn't match; then we find
|
|
113
|
-
// the first non-matching bit and use that to calculate the total
|
|
114
|
-
// length of the match.
|
|
115
|
-
while (SNAPPY_PREDICT_TRUE(s2 <= s2_limit - 8)) {
|
|
116
|
-
if (UNALIGNED_LOAD64(s2) == UNALIGNED_LOAD64(s1 + matched)) {
|
|
117
|
-
s2 += 8;
|
|
118
|
-
matched += 8;
|
|
119
|
-
} else {
|
|
120
|
-
uint64 x = UNALIGNED_LOAD64(s2) ^ UNALIGNED_LOAD64(s1 + matched);
|
|
121
|
-
int matching_bits = Bits::FindLSBSetNonZero64(x);
|
|
122
|
-
matched += matching_bits >> 3;
|
|
123
|
-
assert(matched >= 8);
|
|
124
|
-
return std::pair<size_t, bool>(matched, false);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
while (SNAPPY_PREDICT_TRUE(s2 < s2_limit)) {
|
|
128
|
-
if (s1[matched] == *s2) {
|
|
129
|
-
++s2;
|
|
130
|
-
++matched;
|
|
131
|
-
} else {
|
|
132
|
-
return std::pair<size_t, bool>(matched, matched < 8);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return std::pair<size_t, bool>(matched, matched < 8);
|
|
136
|
-
}
|
|
137
|
-
#else
|
|
138
|
-
static inline std::pair<size_t, bool> FindMatchLength(const char* s1,
|
|
139
|
-
const char* s2,
|
|
140
|
-
const char* s2_limit) {
|
|
141
|
-
// Implementation based on the x86-64 version, above.
|
|
142
|
-
assert(s2_limit >= s2);
|
|
143
|
-
int matched = 0;
|
|
144
|
-
|
|
145
|
-
while (s2 <= s2_limit - 4 &&
|
|
146
|
-
UNALIGNED_LOAD32(s2) == UNALIGNED_LOAD32(s1 + matched)) {
|
|
147
|
-
s2 += 4;
|
|
148
|
-
matched += 4;
|
|
149
|
-
}
|
|
150
|
-
if (LittleEndian::IsLittleEndian() && s2 <= s2_limit - 4) {
|
|
151
|
-
uint32 x = UNALIGNED_LOAD32(s2) ^ UNALIGNED_LOAD32(s1 + matched);
|
|
152
|
-
int matching_bits = Bits::FindLSBSetNonZero(x);
|
|
153
|
-
matched += matching_bits >> 3;
|
|
154
|
-
} else {
|
|
155
|
-
while ((s2 < s2_limit) && (s1[matched] == *s2)) {
|
|
156
|
-
++s2;
|
|
157
|
-
++matched;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return std::pair<size_t, bool>(matched, matched < 8);
|
|
161
|
-
}
|
|
162
|
-
#endif
|
|
163
|
-
|
|
164
|
-
// Lookup tables for decompression code. Give --snappy_dump_decompression_table
|
|
165
|
-
// to the unit test to recompute char_table.
|
|
166
|
-
|
|
167
|
-
enum {
|
|
168
|
-
LITERAL = 0,
|
|
169
|
-
COPY_1_BYTE_OFFSET = 1, // 3 bit length + 3 bits of offset in opcode
|
|
170
|
-
COPY_2_BYTE_OFFSET = 2,
|
|
171
|
-
COPY_4_BYTE_OFFSET = 3
|
|
172
|
-
};
|
|
173
|
-
static const int kMaximumTagLength = 5; // COPY_4_BYTE_OFFSET plus the actual offset.
|
|
174
|
-
|
|
175
|
-
// Data stored per entry in lookup table:
|
|
176
|
-
// Range Bits-used Description
|
|
177
|
-
// ------------------------------------
|
|
178
|
-
// 1..64 0..7 Literal/copy length encoded in opcode byte
|
|
179
|
-
// 0..7 8..10 Copy offset encoded in opcode byte / 256
|
|
180
|
-
// 0..4 11..13 Extra bytes after opcode
|
|
181
|
-
//
|
|
182
|
-
// We use eight bits for the length even though 7 would have sufficed
|
|
183
|
-
// because of efficiency reasons:
|
|
184
|
-
// (1) Extracting a byte is faster than a bit-field
|
|
185
|
-
// (2) It properly aligns copy offset so we do not need a <<8
|
|
186
|
-
static const uint16 char_table[256] = {
|
|
187
|
-
0x0001, 0x0804, 0x1001, 0x2001, 0x0002, 0x0805, 0x1002, 0x2002,
|
|
188
|
-
0x0003, 0x0806, 0x1003, 0x2003, 0x0004, 0x0807, 0x1004, 0x2004,
|
|
189
|
-
0x0005, 0x0808, 0x1005, 0x2005, 0x0006, 0x0809, 0x1006, 0x2006,
|
|
190
|
-
0x0007, 0x080a, 0x1007, 0x2007, 0x0008, 0x080b, 0x1008, 0x2008,
|
|
191
|
-
0x0009, 0x0904, 0x1009, 0x2009, 0x000a, 0x0905, 0x100a, 0x200a,
|
|
192
|
-
0x000b, 0x0906, 0x100b, 0x200b, 0x000c, 0x0907, 0x100c, 0x200c,
|
|
193
|
-
0x000d, 0x0908, 0x100d, 0x200d, 0x000e, 0x0909, 0x100e, 0x200e,
|
|
194
|
-
0x000f, 0x090a, 0x100f, 0x200f, 0x0010, 0x090b, 0x1010, 0x2010,
|
|
195
|
-
0x0011, 0x0a04, 0x1011, 0x2011, 0x0012, 0x0a05, 0x1012, 0x2012,
|
|
196
|
-
0x0013, 0x0a06, 0x1013, 0x2013, 0x0014, 0x0a07, 0x1014, 0x2014,
|
|
197
|
-
0x0015, 0x0a08, 0x1015, 0x2015, 0x0016, 0x0a09, 0x1016, 0x2016,
|
|
198
|
-
0x0017, 0x0a0a, 0x1017, 0x2017, 0x0018, 0x0a0b, 0x1018, 0x2018,
|
|
199
|
-
0x0019, 0x0b04, 0x1019, 0x2019, 0x001a, 0x0b05, 0x101a, 0x201a,
|
|
200
|
-
0x001b, 0x0b06, 0x101b, 0x201b, 0x001c, 0x0b07, 0x101c, 0x201c,
|
|
201
|
-
0x001d, 0x0b08, 0x101d, 0x201d, 0x001e, 0x0b09, 0x101e, 0x201e,
|
|
202
|
-
0x001f, 0x0b0a, 0x101f, 0x201f, 0x0020, 0x0b0b, 0x1020, 0x2020,
|
|
203
|
-
0x0021, 0x0c04, 0x1021, 0x2021, 0x0022, 0x0c05, 0x1022, 0x2022,
|
|
204
|
-
0x0023, 0x0c06, 0x1023, 0x2023, 0x0024, 0x0c07, 0x1024, 0x2024,
|
|
205
|
-
0x0025, 0x0c08, 0x1025, 0x2025, 0x0026, 0x0c09, 0x1026, 0x2026,
|
|
206
|
-
0x0027, 0x0c0a, 0x1027, 0x2027, 0x0028, 0x0c0b, 0x1028, 0x2028,
|
|
207
|
-
0x0029, 0x0d04, 0x1029, 0x2029, 0x002a, 0x0d05, 0x102a, 0x202a,
|
|
208
|
-
0x002b, 0x0d06, 0x102b, 0x202b, 0x002c, 0x0d07, 0x102c, 0x202c,
|
|
209
|
-
0x002d, 0x0d08, 0x102d, 0x202d, 0x002e, 0x0d09, 0x102e, 0x202e,
|
|
210
|
-
0x002f, 0x0d0a, 0x102f, 0x202f, 0x0030, 0x0d0b, 0x1030, 0x2030,
|
|
211
|
-
0x0031, 0x0e04, 0x1031, 0x2031, 0x0032, 0x0e05, 0x1032, 0x2032,
|
|
212
|
-
0x0033, 0x0e06, 0x1033, 0x2033, 0x0034, 0x0e07, 0x1034, 0x2034,
|
|
213
|
-
0x0035, 0x0e08, 0x1035, 0x2035, 0x0036, 0x0e09, 0x1036, 0x2036,
|
|
214
|
-
0x0037, 0x0e0a, 0x1037, 0x2037, 0x0038, 0x0e0b, 0x1038, 0x2038,
|
|
215
|
-
0x0039, 0x0f04, 0x1039, 0x2039, 0x003a, 0x0f05, 0x103a, 0x203a,
|
|
216
|
-
0x003b, 0x0f06, 0x103b, 0x203b, 0x003c, 0x0f07, 0x103c, 0x203c,
|
|
217
|
-
0x0801, 0x0f08, 0x103d, 0x203d, 0x1001, 0x0f09, 0x103e, 0x203e,
|
|
218
|
-
0x1801, 0x0f0a, 0x103f, 0x203f, 0x2001, 0x0f0b, 0x1040, 0x2040
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
} // end namespace internal
|
|
222
|
-
} // end namespace snappy
|
|
223
|
-
|
|
224
|
-
#endif // THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_
|