Path: blob/master/Utilities/cmzstd/lib/compress/zstd_ldm.h
5019 views
/*1* Copyright (c) Meta Platforms, Inc. and affiliates.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef ZSTD_LDM_H11#define ZSTD_LDM_H1213#include "zstd_compress_internal.h" /* ldmParams_t, U32 */14#include "../zstd.h" /* ZSTD_CCtx, size_t */1516/*-*************************************17* Long distance matching18***************************************/1920#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT2122void ZSTD_ldm_fillHashTable(23ldmState_t* state, const BYTE* ip,24const BYTE* iend, ldmParams_t const* params);2526/**27* ZSTD_ldm_generateSequences():28*29* Generates the sequences using the long distance match finder.30* Generates long range matching sequences in `sequences`, which parse a prefix31* of the source. `sequences` must be large enough to store every sequence,32* which can be checked with `ZSTD_ldm_getMaxNbSeq()`.33* @returns 0 or an error code.34*35* NOTE: The user must have called ZSTD_window_update() for all of the input36* they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.37* NOTE: This function returns an error if it runs out of space to store38* sequences.39*/40size_t ZSTD_ldm_generateSequences(41ldmState_t* ldms, RawSeqStore_t* sequences,42ldmParams_t const* params, void const* src, size_t srcSize);4344/**45* ZSTD_ldm_blockCompress():46*47* Compresses a block using the predefined sequences, along with a secondary48* block compressor. The literals section of every sequence is passed to the49* secondary block compressor, and those sequences are interspersed with the50* predefined sequences. Returns the length of the last literals.51* Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.52* `rawSeqStore.seq` may also be updated to split the last sequence between two53* blocks.54* @return The length of the last literals.55*56* NOTE: The source must be at most the maximum block size, but the predefined57* sequences can be any size, and may be longer than the block. In the case that58* they are longer than the block, the last sequences may need to be split into59* two. We handle that case correctly, and update `rawSeqStore` appropriately.60* NOTE: This function does not return any errors.61*/62size_t ZSTD_ldm_blockCompress(RawSeqStore_t* rawSeqStore,63ZSTD_MatchState_t* ms, SeqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],64ZSTD_ParamSwitch_e useRowMatchFinder,65void const* src, size_t srcSize);6667/**68* ZSTD_ldm_skipSequences():69*70* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.71* Avoids emitting matches less than `minMatch` bytes.72* Must be called for data that is not passed to ZSTD_ldm_blockCompress().73*/74void ZSTD_ldm_skipSequences(RawSeqStore_t* rawSeqStore, size_t srcSize,75U32 const minMatch);7677/* ZSTD_ldm_skipRawSeqStoreBytes():78* Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.79* Not to be used in conjunction with ZSTD_ldm_skipSequences().80* Must be called for data with is not passed to ZSTD_ldm_blockCompress().81*/82void ZSTD_ldm_skipRawSeqStoreBytes(RawSeqStore_t* rawSeqStore, size_t nbBytes);8384/** ZSTD_ldm_getTableSize() :85* Estimate the space needed for long distance matching tables or 0 if LDM is86* disabled.87*/88size_t ZSTD_ldm_getTableSize(ldmParams_t params);8990/** ZSTD_ldm_getSeqSpace() :91* Return an upper bound on the number of sequences that can be produced by92* the long distance matcher, or 0 if LDM is disabled.93*/94size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);9596/** ZSTD_ldm_adjustParameters() :97* If the params->hashRateLog is not set, set it to its default value based on98* windowLog and params->hashLog.99*100* Ensures that params->bucketSizeLog is <= params->hashLog (setting it to101* params->hashLog if it is not).102*103* Ensures that the minMatchLength >= targetLength during optimal parsing.104*/105void ZSTD_ldm_adjustParameters(ldmParams_t* params,106ZSTD_compressionParameters const* cParams);107108#endif /* ZSTD_FAST_H */109110111