zstd_ldm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 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. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. #ifndef ZSTD_LDM_H
  11. #define ZSTD_LDM_H
  12. #include "zstd_compress_internal.h" /* ldmParams_t, U32 */
  13. #include <linux/zstd.h> /* ZSTD_CCtx, size_t */
  14. /*-*************************************
  15. * Long distance matching
  16. ***************************************/
  17. #define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
  18. void ZSTD_ldm_fillHashTable(
  19. ldmState_t* state, const BYTE* ip,
  20. const BYTE* iend, ldmParams_t const* params);
  21. /*
  22. * ZSTD_ldm_generateSequences():
  23. *
  24. * Generates the sequences using the long distance match finder.
  25. * Generates long range matching sequences in `sequences`, which parse a prefix
  26. * of the source. `sequences` must be large enough to store every sequence,
  27. * which can be checked with `ZSTD_ldm_getMaxNbSeq()`.
  28. * @returns 0 or an error code.
  29. *
  30. * NOTE: The user must have called ZSTD_window_update() for all of the input
  31. * they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.
  32. * NOTE: This function returns an error if it runs out of space to store
  33. * sequences.
  34. */
  35. size_t ZSTD_ldm_generateSequences(
  36. ldmState_t* ldms, rawSeqStore_t* sequences,
  37. ldmParams_t const* params, void const* src, size_t srcSize);
  38. /*
  39. * ZSTD_ldm_blockCompress():
  40. *
  41. * Compresses a block using the predefined sequences, along with a secondary
  42. * block compressor. The literals section of every sequence is passed to the
  43. * secondary block compressor, and those sequences are interspersed with the
  44. * predefined sequences. Returns the length of the last literals.
  45. * Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.
  46. * `rawSeqStore.seq` may also be updated to split the last sequence between two
  47. * blocks.
  48. * @return The length of the last literals.
  49. *
  50. * NOTE: The source must be at most the maximum block size, but the predefined
  51. * sequences can be any size, and may be longer than the block. In the case that
  52. * they are longer than the block, the last sequences may need to be split into
  53. * two. We handle that case correctly, and update `rawSeqStore` appropriately.
  54. * NOTE: This function does not return any errors.
  55. */
  56. size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
  57. ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
  58. void const* src, size_t srcSize);
  59. /*
  60. * ZSTD_ldm_skipSequences():
  61. *
  62. * Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
  63. * Avoids emitting matches less than `minMatch` bytes.
  64. * Must be called for data that is not passed to ZSTD_ldm_blockCompress().
  65. */
  66. void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
  67. U32 const minMatch);
  68. /* ZSTD_ldm_skipRawSeqStoreBytes():
  69. * Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.
  70. * Not to be used in conjunction with ZSTD_ldm_skipSequences().
  71. * Must be called for data with is not passed to ZSTD_ldm_blockCompress().
  72. */
  73. void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);
  74. /* ZSTD_ldm_getTableSize() :
  75. * Estimate the space needed for long distance matching tables or 0 if LDM is
  76. * disabled.
  77. */
  78. size_t ZSTD_ldm_getTableSize(ldmParams_t params);
  79. /* ZSTD_ldm_getSeqSpace() :
  80. * Return an upper bound on the number of sequences that can be produced by
  81. * the long distance matcher, or 0 if LDM is disabled.
  82. */
  83. size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
  84. /* ZSTD_ldm_adjustParameters() :
  85. * If the params->hashRateLog is not set, set it to its default value based on
  86. * windowLog and params->hashLog.
  87. *
  88. * Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
  89. * params->hashLog if it is not).
  90. *
  91. * Ensures that the minMatchLength >= targetLength during optimal parsing.
  92. */
  93. void ZSTD_ldm_adjustParameters(ldmParams_t* params,
  94. ZSTD_compressionParameters const* cParams);
  95. #endif /* ZSTD_FAST_H */