xref: /freebsd/sys/contrib/zstd/lib/compress/zstd_ldm.h (revision 0c16b53773565120a8f80a31a0af2ef56ccd368e)
1*0c16b537SWarner Losh /*
2*0c16b537SWarner Losh  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3*0c16b537SWarner Losh  * All rights reserved.
4*0c16b537SWarner Losh  *
5*0c16b537SWarner Losh  * This source code is licensed under both the BSD-style license (found in the
6*0c16b537SWarner Losh  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*0c16b537SWarner Losh  * in the COPYING file in the root directory of this source tree).
8*0c16b537SWarner Losh  */
9*0c16b537SWarner Losh 
10*0c16b537SWarner Losh #ifndef ZSTD_LDM_H
11*0c16b537SWarner Losh #define ZSTD_LDM_H
12*0c16b537SWarner Losh 
13*0c16b537SWarner Losh #include "zstd_compress.h"
14*0c16b537SWarner Losh 
15*0c16b537SWarner Losh #if defined (__cplusplus)
16*0c16b537SWarner Losh extern "C" {
17*0c16b537SWarner Losh #endif
18*0c16b537SWarner Losh 
19*0c16b537SWarner Losh /*-*************************************
20*0c16b537SWarner Losh *  Long distance matching
21*0c16b537SWarner Losh ***************************************/
22*0c16b537SWarner Losh 
23*0c16b537SWarner Losh #define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_DEFAULTMAX
24*0c16b537SWarner Losh #define ZSTD_LDM_HASHEVERYLOG_NOTSET 9999
25*0c16b537SWarner Losh 
26*0c16b537SWarner Losh /** ZSTD_compressBlock_ldm_generic() :
27*0c16b537SWarner Losh  *
28*0c16b537SWarner Losh  *  This is a block compressor intended for long distance matching.
29*0c16b537SWarner Losh  *
30*0c16b537SWarner Losh  *  The function searches for matches of length at least
31*0c16b537SWarner Losh  *  ldmParams.minMatchLength using a hash table in cctx->ldmState.
32*0c16b537SWarner Losh  *  Matches can be at a distance of up to cParams.windowLog.
33*0c16b537SWarner Losh  *
34*0c16b537SWarner Losh  *  Upon finding a match, the unmatched literals are compressed using a
35*0c16b537SWarner Losh  *  ZSTD_blockCompressor (depending on the strategy in the compression
36*0c16b537SWarner Losh  *  parameters), which stores the matched sequences. The "long distance"
37*0c16b537SWarner Losh  *  match is then stored with the remaining literals from the
38*0c16b537SWarner Losh  *  ZSTD_blockCompressor. */
39*0c16b537SWarner Losh size_t ZSTD_compressBlock_ldm(ZSTD_CCtx* cctx, const void* src, size_t srcSize);
40*0c16b537SWarner Losh size_t ZSTD_compressBlock_ldm_extDict(ZSTD_CCtx* ctx,
41*0c16b537SWarner Losh                                       const void* src, size_t srcSize);
42*0c16b537SWarner Losh 
43*0c16b537SWarner Losh /** ZSTD_ldm_initializeParameters() :
44*0c16b537SWarner Losh  *  Initialize the long distance matching parameters to their default values. */
45*0c16b537SWarner Losh size_t ZSTD_ldm_initializeParameters(ldmParams_t* params, U32 enableLdm);
46*0c16b537SWarner Losh 
47*0c16b537SWarner Losh /** ZSTD_ldm_getTableSize() :
48*0c16b537SWarner Losh  *  Estimate the space needed for long distance matching tables. */
49*0c16b537SWarner Losh size_t ZSTD_ldm_getTableSize(U32 hashLog, U32 bucketSizeLog);
50*0c16b537SWarner Losh 
51*0c16b537SWarner Losh /** ZSTD_ldm_getTableSize() :
52*0c16b537SWarner Losh  *  Return prime8bytes^(minMatchLength-1) */
53*0c16b537SWarner Losh U64 ZSTD_ldm_getHashPower(U32 minMatchLength);
54*0c16b537SWarner Losh 
55*0c16b537SWarner Losh /** ZSTD_ldm_adjustParameters() :
56*0c16b537SWarner Losh  *  If the params->hashEveryLog is not set, set it to its default value based on
57*0c16b537SWarner Losh  *  windowLog and params->hashLog.
58*0c16b537SWarner Losh  *
59*0c16b537SWarner Losh  *  Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
60*0c16b537SWarner Losh  *  params->hashLog if it is not). */
61*0c16b537SWarner Losh void ZSTD_ldm_adjustParameters(ldmParams_t* params, U32 windowLog);
62*0c16b537SWarner Losh 
63*0c16b537SWarner Losh #if defined (__cplusplus)
64*0c16b537SWarner Losh }
65*0c16b537SWarner Losh #endif
66*0c16b537SWarner Losh 
67*0c16b537SWarner Losh #endif /* ZSTD_FAST_H */
68