You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zstd_ldm.h 4.3KB

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