zstd_ldm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. */
  9. #ifndef ZSTD_LDM_H
  10. #define ZSTD_LDM_H
  11. #if defined (__cplusplus)
  12. extern "C" {
  13. #endif
  14. #include "zstd_compress_internal.h" /* ldmParams_t, U32 */
  15. #include "zstd.h" /* ZSTD_CCtx, size_t */
  16. /*-*************************************
  17. * Long distance matching
  18. ***************************************/
  19. #define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_DEFAULTMAX
  20. /**
  21. * ZSTD_ldm_generateSequences():
  22. *
  23. * Generates the sequences using the long distance match finder.
  24. * Generates long range matching sequences in `sequences`, which parse a prefix
  25. * of the source. `sequences` must be large enough to store every sequence,
  26. * which can be checked with `ZSTD_ldm_getMaxNbSeq()`.
  27. * @returns 0 or an error code.
  28. *
  29. * NOTE: The user must have called ZSTD_window_update() for all of the input
  30. * they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.
  31. * NOTE: This function returns an error if it runs out of space to store
  32. * sequences.
  33. */
  34. size_t ZSTD_ldm_generateSequences(
  35. ldmState_t* ldms, rawSeqStore_t* sequences,
  36. ldmParams_t const* params, void const* src, size_t srcSize);
  37. /**
  38. * ZSTD_ldm_blockCompress():
  39. *
  40. * Compresses a block using the predefined sequences, along with a secondary
  41. * block compressor. The literals section of every sequence is passed to the
  42. * secondary block compressor, and those sequences are interspersed with the
  43. * predefined sequences. Returns the length of the last literals.
  44. * Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.
  45. * `rawSeqStore.seq` may also be updated to split the last sequence between two
  46. * blocks.
  47. * @return The length of the last literals.
  48. *
  49. * NOTE: The source must be at most the maximum block size, but the predefined
  50. * sequences can be any size, and may be longer than the block. In the case that
  51. * they are longer than the block, the last sequences may need to be split into
  52. * two. We handle that case correctly, and update `rawSeqStore` appropriately.
  53. * NOTE: This function does not return any errors.
  54. */
  55. size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
  56. ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
  57. ZSTD_compressionParameters const* cParams,
  58. void const* src, size_t srcSize,
  59. int const extDict);
  60. /**
  61. * ZSTD_ldm_skipSequences():
  62. *
  63. * Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
  64. * Avoids emitting matches less than `minMatch` bytes.
  65. * Must be called for data with is not passed to ZSTD_ldm_blockCompress().
  66. */
  67. void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
  68. U32 const minMatch);
  69. /** ZSTD_ldm_getTableSize() :
  70. * Estimate the space needed for long distance matching tables or 0 if LDM is
  71. * disabled.
  72. */
  73. size_t ZSTD_ldm_getTableSize(ldmParams_t params);
  74. /** ZSTD_ldm_getSeqSpace() :
  75. * Return an upper bound on the number of sequences that can be produced by
  76. * the long distance matcher, or 0 if LDM is disabled.
  77. */
  78. size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
  79. /** ZSTD_ldm_getTableSize() :
  80. * Return prime8bytes^(minMatchLength-1) */
  81. U64 ZSTD_ldm_getHashPower(U32 minMatchLength);
  82. /** ZSTD_ldm_adjustParameters() :
  83. * If the params->hashEveryLog is not set, set it to its default value based on
  84. * windowLog and params->hashLog.
  85. *
  86. * Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
  87. * params->hashLog if it is not).
  88. *
  89. * Ensures that the minMatchLength >= targetLength during optimal parsing.
  90. */
  91. void ZSTD_ldm_adjustParameters(ldmParams_t* params,
  92. ZSTD_compressionParameters const* cParams);
  93. #if defined (__cplusplus)
  94. }
  95. #endif
  96. #endif /* ZSTD_FAST_H */