Path: blob/master/Utilities/cmzstd/lib/compress/zstd_ldm.h
3158 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#if defined (__cplusplus)14extern "C" {15#endif1617#include "zstd_compress_internal.h" /* ldmParams_t, U32 */18#include "../zstd.h" /* ZSTD_CCtx, size_t */1920/*-*************************************21* Long distance matching22***************************************/2324#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT2526void ZSTD_ldm_fillHashTable(27ldmState_t* state, const BYTE* ip,28const BYTE* iend, ldmParams_t const* params);2930/**31* ZSTD_ldm_generateSequences():32*33* Generates the sequences using the long distance match finder.34* Generates long range matching sequences in `sequences`, which parse a prefix35* of the source. `sequences` must be large enough to store every sequence,36* which can be checked with `ZSTD_ldm_getMaxNbSeq()`.37* @returns 0 or an error code.38*39* NOTE: The user must have called ZSTD_window_update() for all of the input40* they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.41* NOTE: This function returns an error if it runs out of space to store42* sequences.43*/44size_t ZSTD_ldm_generateSequences(45ldmState_t* ldms, rawSeqStore_t* sequences,46ldmParams_t const* params, void const* src, size_t srcSize);4748/**49* ZSTD_ldm_blockCompress():50*51* Compresses a block using the predefined sequences, along with a secondary52* block compressor. The literals section of every sequence is passed to the53* secondary block compressor, and those sequences are interspersed with the54* predefined sequences. Returns the length of the last literals.55* Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.56* `rawSeqStore.seq` may also be updated to split the last sequence between two57* blocks.58* @return The length of the last literals.59*60* NOTE: The source must be at most the maximum block size, but the predefined61* sequences can be any size, and may be longer than the block. In the case that62* they are longer than the block, the last sequences may need to be split into63* two. We handle that case correctly, and update `rawSeqStore` appropriately.64* NOTE: This function does not return any errors.65*/66size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,67ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],68ZSTD_paramSwitch_e useRowMatchFinder,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 that is not passed to ZSTD_ldm_blockCompress().77*/78void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,79U32 const minMatch);8081/* ZSTD_ldm_skipRawSeqStoreBytes():82* Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.83* Not to be used in conjunction with ZSTD_ldm_skipSequences().84* Must be called for data with is not passed to ZSTD_ldm_blockCompress().85*/86void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);8788/** ZSTD_ldm_getTableSize() :89* Estimate the space needed for long distance matching tables or 0 if LDM is90* disabled.91*/92size_t ZSTD_ldm_getTableSize(ldmParams_t params);9394/** ZSTD_ldm_getSeqSpace() :95* Return an upper bound on the number of sequences that can be produced by96* the long distance matcher, or 0 if LDM is disabled.97*/98size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);99100/** ZSTD_ldm_adjustParameters() :101* If the params->hashRateLog is not set, set it to its default value based on102* windowLog and params->hashLog.103*104* Ensures that params->bucketSizeLog is <= params->hashLog (setting it to105* params->hashLog if it is not).106*107* Ensures that the minMatchLength >= targetLength during optimal parsing.108*/109void ZSTD_ldm_adjustParameters(ldmParams_t* params,110ZSTD_compressionParameters const* cParams);111112#if defined (__cplusplus)113}114#endif115116#endif /* ZSTD_FAST_H */117118119