1 | /* ---------- |
2 | * pg_lzcompress.h - |
3 | * |
4 | * Definitions for the builtin LZ compressor |
5 | * |
6 | * src/include/common/pg_lzcompress.h |
7 | * ---------- |
8 | */ |
9 | |
10 | #ifndef _PG_LZCOMPRESS_H_ |
11 | #define _PG_LZCOMPRESS_H_ |
12 | |
13 | |
14 | /* ---------- |
15 | * PGLZ_MAX_OUTPUT - |
16 | * |
17 | * Macro to compute the buffer size required by pglz_compress(). |
18 | * We allow 4 bytes for overrun before detecting compression failure. |
19 | * ---------- |
20 | */ |
21 | #define PGLZ_MAX_OUTPUT(_dlen) ((_dlen) + 4) |
22 | |
23 | |
24 | /* ---------- |
25 | * PGLZ_Strategy - |
26 | * |
27 | * Some values that control the compression algorithm. |
28 | * |
29 | * min_input_size Minimum input data size to consider compression. |
30 | * |
31 | * max_input_size Maximum input data size to consider compression. |
32 | * |
33 | * min_comp_rate Minimum compression rate (0-99%) to require. |
34 | * Regardless of min_comp_rate, the output must be |
35 | * smaller than the input, else we don't store |
36 | * compressed. |
37 | * |
38 | * first_success_by Abandon compression if we find no compressible |
39 | * data within the first this-many bytes. |
40 | * |
41 | * match_size_good The initial GOOD match size when starting history |
42 | * lookup. When looking up the history to find a |
43 | * match that could be expressed as a tag, the |
44 | * algorithm does not always walk back entirely. |
45 | * A good match fast is usually better than the |
46 | * best possible one very late. For each iteration |
47 | * in the lookup, this value is lowered so the |
48 | * longer the lookup takes, the smaller matches |
49 | * are considered good. |
50 | * |
51 | * match_size_drop The percentage by which match_size_good is lowered |
52 | * after each history check. Allowed values are |
53 | * 0 (no change until end) to 100 (only check |
54 | * latest history entry at all). |
55 | * ---------- |
56 | */ |
57 | typedef struct PGLZ_Strategy |
58 | { |
59 | int32 min_input_size; |
60 | int32 max_input_size; |
61 | int32 min_comp_rate; |
62 | int32 first_success_by; |
63 | int32 match_size_good; |
64 | int32 match_size_drop; |
65 | } PGLZ_Strategy; |
66 | |
67 | |
68 | /* ---------- |
69 | * The standard strategies |
70 | * |
71 | * PGLZ_strategy_default Recommended default strategy for TOAST. |
72 | * |
73 | * PGLZ_strategy_always Try to compress inputs of any length. |
74 | * Fallback to uncompressed storage only if |
75 | * output would be larger than input. |
76 | * ---------- |
77 | */ |
78 | extern const PGLZ_Strategy *const PGLZ_strategy_default; |
79 | extern const PGLZ_Strategy *const PGLZ_strategy_always; |
80 | |
81 | |
82 | /* ---------- |
83 | * Global function declarations |
84 | * ---------- |
85 | */ |
86 | extern int32 pglz_compress(const char *source, int32 slen, char *dest, |
87 | const PGLZ_Strategy *strategy); |
88 | extern int32 pglz_decompress(const char *source, int32 slen, char *dest, |
89 | int32 rawsize, bool check_complete); |
90 | |
91 | #endif /* _PG_LZCOMPRESS_H_ */ |
92 | |