Debian Codegraph @

src/bitshuffle.h

raw
1 /*
2 * Bitshuffle - Filter for improving compression of typed binary data.
3 *
4 * This file is part of Bitshuffle
5 * Author: Kiyoshi Masui <[email protected]>
6 * Website: https://www.github.com/kiyo-masui/bitshuffle
7 * Created: 2014
8 *
9 * See LICENSE file for details about copyright and rights to use.
10 *
11 *
12 * Header File
13 *
14 * Worker routines return an int64_t which is the number of bytes processed
15 * if positive or an error code if negative.
16 *
17 * Error codes:
18 * -1 : Failed to allocate memory.
19 * -11 : Missing SSE.
20 * -12 : Missing AVX.
21 * -80 : Input size not a multiple of 8.
22 * -81 : block_size not multiple of 8.
23 * -91 : Decompression error, wrong number of bytes processed.
24 * -1YYY : Error internal to compression routine with error code -YYY.
25 */
26
27
28 #ifndef BITSHUFFLE_H
29 #define BITSHUFFLE_H
30
31 #include <stdlib.h>
32 #include "bitshuffle_core.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /*
39 * ---- LZ4 Interface ----
40 */
41
42 /* ---- bshuf_compress_lz4_bound ----
43 *
44 * Bound on size of data compressed with *bshuf_compress_lz4*.
45 *
46 * Parameters
47 * ----------
48 * size : number of elements in input
49 * elem_size : element size of typed data
50 * block_size : Process in blocks of this many elements. Pass 0 to
51 * select automatically (recommended).
52 *
53 * Returns
54 * -------
55 * Bound on compressed data size.
56 *
57 */
58 size_t bshuf_compress_lz4_bound(const size_t size,
59 const size_t elem_size, size_t block_size);
60
61
62 /* ---- bshuf_compress_lz4 ----
63 *
64 * Bitshuffled and compress the data using LZ4.
65 *
66 * Transpose within elements, in blocks of data of *block_size* elements then
67 * compress the blocks using LZ4. In the output buffer, each block is prefixed
68 * by a 4 byte integer giving the compressed size of that block.
69 *
70 * Output buffer must be large enough to hold the compressed data. This could
71 * be in principle substantially larger than the input buffer. Use the routine
72 * *bshuf_compress_lz4_bound* to get an upper limit.
73 *
74 * Parameters
75 * ----------
76 * in : input buffer, must be of size * elem_size bytes
77 * out : output buffer, must be large enough to hold data.
78 * size : number of elements in input
79 * elem_size : element size of typed data
80 * block_size : Process in blocks of this many elements. Pass 0 to
81 * select automatically (recommended).
82 *
83 * Returns
84 * -------
85 * number of bytes used in output buffer, negative error-code if failed.
86 *
87 */
88 int64_t bshuf_compress_lz4(const void* in, void* out, const size_t size, const size_t
89 elem_size, size_t block_size);
90
91
92 /* ---- bshuf_decompress_lz4 ----
93 *
94 * Undo compression and bitshuffling.
95 *
96 * Decompress data then un-bitshuffle it in blocks of *block_size* elements.
97 *
98 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size*
99 * must patch the parameters used to compress the data.
100 *
101 * Parameters
102 * ----------
103 * in : input buffer
104 * out : output buffer, must be of size * elem_size bytes
105 * size : number of elements in input
106 * elem_size : element size of typed data
107 * block_size : Process in blocks of this many elements. Pass 0 to
108 * select automatically (recommended).
109 *
110 * Returns
111 * -------
112 * number of bytes consumed in *input* buffer, negative error-code if failed.
113 *
114 */
115 int64_t bshuf_decompress_lz4(const void* in, void* out, const size_t size,
116 const size_t elem_size, size_t block_size);
117
118 /*
119 * ---- ZSTD Interface ----
120 */
121
122 #ifdef ZSTD_SUPPORT
123 /* ---- bshuf_compress_zstd_bound ----
124 *
125 * Bound on size of data compressed with *bshuf_compress_zstd*.
126 *
127 * Parameters
128 * ----------
129 * size : number of elements in input
130 * elem_size : element size of typed data
131 * block_size : Process in blocks of this many elements. Pass 0 to
132 * select automatically (recommended).
133 *
134 * Returns
135 * -------
136 * Bound on compressed data size.
137 *
138 */
139 size_t bshuf_compress_zstd_bound(const size_t size,
140 const size_t elem_size, size_t block_size);
141
142 /* ---- bshuf_compress_zstd ----
143 *
144 * Bitshuffled and compress the data using zstd.
145 *
146 * Transpose within elements, in blocks of data of *block_size* elements then
147 * compress the blocks using ZSTD. In the output buffer, each block is prefixed
148 * by a 4 byte integer giving the compressed size of that block.
149 *
150 * Output buffer must be large enough to hold the compressed data. This could
151 * be in principle substantially larger than the input buffer. Use the routine
152 * *bshuf_compress_zstd_bound* to get an upper limit.
153 *
154 * Parameters
155 * ----------
156 * in : input buffer, must be of size * elem_size bytes
157 * out : output buffer, must be large enough to hold data.
158 * size : number of elements in input
159 * elem_size : element size of typed data
160 * block_size : Process in blocks of this many elements. Pass 0 to
161 * select automatically (recommended).
162 * comp_lvl : compression level applied
163 *
164 * Returns
165 * -------
166 * number of bytes used in output buffer, negative error-code if failed.
167 *
168 */
169 int64_t bshuf_compress_zstd(const void* in, void* out, const size_t size, const size_t
170 elem_size, size_t block_size, const int comp_lvl);
171
172
173 /* ---- bshuf_decompress_zstd ----
174 *
175 * Undo compression and bitshuffling.
176 *
177 * Decompress data then un-bitshuffle it in blocks of *block_size* elements.
178 *
179 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size*
180 * must patch the parameters used to compress the data.
181 *
182 * Parameters
183 * ----------
184 * in : input buffer
185 * out : output buffer, must be of size * elem_size bytes
186 * size : number of elements in input
187 * elem_size : element size of typed data
188 * block_size : Process in blocks of this many elements. Pass 0 to
189 * select automatically (recommended).
190 *
191 * Returns
192 * -------
193 * number of bytes consumed in *input* buffer, negative error-code if failed.
194 *
195 */
196 int64_t bshuf_decompress_zstd(const void* in, void* out, const size_t size,
197 const size_t elem_size, size_t block_size);
198
199 #endif // ZSTD_SUPPORT
200
201 #ifdef __cplusplus
202 } // extern "C"
203 #endif
204
205 #endif // BITSHUFFLE_H