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