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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2016-2020, 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. #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. void const* src, size_t srcSize);
  62. /**
  63. * ZSTD_ldm_skipSequences():
  64. *
  65. * Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
  66. * Avoids emitting matches less than `minMatch` bytes.
  67. * Must be called for data with is not passed to ZSTD_ldm_blockCompress().
  68. */
  69. void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
  70. U32 const minMatch);
  71. /** ZSTD_ldm_getTableSize() :
  72. * Estimate the space needed for long distance matching tables or 0 if LDM is
  73. * disabled.
  74. */
  75. size_t ZSTD_ldm_getTableSize(ldmParams_t params);
  76. /** ZSTD_ldm_getSeqSpace() :
  77. * Return an upper bound on the number of sequences that can be produced by
  78. * the long distance matcher, or 0 if LDM is disabled.
  79. */
  80. size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
  81. /** ZSTD_ldm_adjustParameters() :
  82. * If the params->hashRateLog is not set, set it to its default value based on
  83. * windowLog and params->hashLog.
  84. *
  85. * Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
  86. * params->hashLog if it is not).
  87. *
  88. * Ensures that the minMatchLength >= targetLength during optimal parsing.
  89. */
  90. void ZSTD_ldm_adjustParameters(ldmParams_t* params,
  91. ZSTD_compressionParameters const* cParams);
  92. #if defined (__cplusplus)
  93. }
  94. #endif
  95. #endif /* ZSTD_FAST_H */