Path: blob/main/sys/contrib/openzfs/module/zstd/lib/compress/zstd_ldm.h
48774 views
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only1/*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 the6* LICENSE file in the root directory of this source tree) and the GPLv2 (found7* 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*/1011#ifndef ZSTD_LDM_H12#define ZSTD_LDM_H1314#if defined (__cplusplus)15extern "C" {16#endif1718#include "zstd_compress_internal.h" /* ldmParams_t, U32 */19#include "../zstd.h" /* ZSTD_CCtx, size_t */2021/*-*************************************22* Long distance matching23***************************************/2425#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT2627void ZSTD_ldm_fillHashTable(28ldmState_t* state, const BYTE* ip,29const BYTE* iend, ldmParams_t const* params);3031/**32* ZSTD_ldm_generateSequences():33*34* Generates the sequences using the long distance match finder.35* Generates long range matching sequences in `sequences`, which parse a prefix36* of the source. `sequences` must be large enough to store every sequence,37* which can be checked with `ZSTD_ldm_getMaxNbSeq()`.38* @returns 0 or an error code.39*40* NOTE: The user must have called ZSTD_window_update() for all of the input41* they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.42* NOTE: This function returns an error if it runs out of space to store43* sequences.44*/45size_t ZSTD_ldm_generateSequences(46ldmState_t* ldms, rawSeqStore_t* sequences,47ldmParams_t const* params, void const* src, size_t srcSize);4849/**50* ZSTD_ldm_blockCompress():51*52* Compresses a block using the predefined sequences, along with a secondary53* block compressor. The literals section of every sequence is passed to the54* secondary block compressor, and those sequences are interspersed with the55* predefined sequences. Returns the length of the last literals.56* Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.57* `rawSeqStore.seq` may also be updated to split the last sequence between two58* blocks.59* @return The length of the last literals.60*61* NOTE: The source must be at most the maximum block size, but the predefined62* sequences can be any size, and may be longer than the block. In the case that63* they are longer than the block, the last sequences may need to be split into64* two. We handle that case correctly, and update `rawSeqStore` appropriately.65* NOTE: This function does not return any errors.66*/67size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,68ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],69void const* src, size_t srcSize);7071/**72* ZSTD_ldm_skipSequences():73*74* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.75* Avoids emitting matches less than `minMatch` bytes.76* Must be called for data with is not passed to ZSTD_ldm_blockCompress().77*/78void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,79U32 const minMatch);808182/** ZSTD_ldm_getTableSize() :83* Estimate the space needed for long distance matching tables or 0 if LDM is84* disabled.85*/86size_t ZSTD_ldm_getTableSize(ldmParams_t params);8788/** ZSTD_ldm_getSeqSpace() :89* Return an upper bound on the number of sequences that can be produced by90* the long distance matcher, or 0 if LDM is disabled.91*/92size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);9394/** ZSTD_ldm_adjustParameters() :95* If the params->hashRateLog is not set, set it to its default value based on96* windowLog and params->hashLog.97*98* Ensures that params->bucketSizeLog is <= params->hashLog (setting it to99* params->hashLog if it is not).100*101* Ensures that the minMatchLength >= targetLength during optimal parsing.102*/103void ZSTD_ldm_adjustParameters(ldmParams_t* params,104ZSTD_compressionParameters const* cParams);105106#if defined (__cplusplus)107}108#endif109110#endif /* ZSTD_FAST_H */111112113