2
0

pg_lzcompress.h 2.7 KB

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