Lines Matching defs:cdict
84 * row-based matchfinder. Unless the cdict is reloaded, we will use
148 ZSTD_freeCDict(cctx->localDict.cdict);
151 cctx->cdict = NULL;
157 size_t const cdictSize = ZSTD_sizeof_CDict(dict.cdict);
1001 RETURN_ERROR_IF(cctx->cdict, stage_wrong,
1002 "Can't override parameters with cdict attached (some must "
1003 "be inherited from the cdict).");
1037 assert(dl->cdict == NULL);
1041 if (dl->cdict != NULL) {
1042 assert(cctx->cdict == dl->cdict);
1047 assert(cctx->cdict == NULL);
1050 dl->cdict = ZSTD_createCDict_advanced2(
1057 RETURN_ERROR_IF(!dl->cdict, memory_allocation, "ZSTD_createCDict_advanced failed");
1058 cctx->cdict = dl->cdict;
1103 size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
1107 /* Free the existing local cdict (if any) to save memory. */
1109 cctx->cdict = cdict;
1946 static int ZSTD_shouldAttachDict(const ZSTD_CDict* cdict,
1950 size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy];
1951 int const dedicatedDictSearch = cdict->matchState.dedicatedDictSearch;
1963 const ZSTD_CDict* cdict,
1971 ZSTD_compressionParameters adjusted_cdict_cParams = cdict->matchState.cParams;
1978 if (cdict->matchState.dedicatedDictSearch) {
1983 cdict->dictContentSize, ZSTD_cpm_attachDict);
1985 params.useRowMatchFinder = cdict->useRowMatchFinder; /* cdict overrides */
1992 { const U32 cdictEnd = (U32)( cdict->matchState.window.nextSrc
1993 - cdict->matchState.window.base);
1994 const U32 cdictLen = cdictEnd - cdict->matchState.window.dictLimit;
2000 cctx->blockState.matchState.dictMatchState = &cdict->matchState;
2013 cctx->dictID = cdict->dictID;
2014 cctx->dictContentSize = cdict->dictContentSize;
2017 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState));
2023 const ZSTD_CDict* cdict,
2028 const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams;
2030 assert(!cdict->matchState.dedicatedDictSearch);
2039 params.useRowMatchFinder = cdict->useRowMatchFinder;
2052 { size_t const chainSize = ZSTD_allocateChainTable(cdict_cParams->strategy, cdict->useRowMatchFinder, 0 /* DDS guaranteed disabled */)
2058 cdict->matchState.hashTable,
2060 /* Do not copy cdict's chainTable if cctx has parameters such that it would not use chainTable */
2063 cdict->matchState.chainTable,
2067 if (ZSTD_rowMatchFinderUsed(cdict_cParams->strategy, cdict->useRowMatchFinder)) {
2070 cdict->matchState.tagTable,
2075 /* Zero the hashTable3, since the cdict never fills it */
2078 assert(cdict->matchState.hashLog3 == 0);
2085 { ZSTD_matchState_t const* srcMatchState = &cdict->matchState;
2092 cctx->dictID = cdict->dictID;
2093 cctx->dictContentSize = cdict->dictContentSize;
2096 ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState, sizeof(cdict->cBlockState));
2105 const ZSTD_CDict* cdict,
2114 if (ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize)) {
2116 cctx, cdict, *params, pledgedSrcSize, zbuff);
2119 cctx, cdict, *params, pledgedSrcSize, zbuff);
4402 const ZSTD_CDict* cdict,
4406 size_t const dictContentSize = cdict ? cdict->dictContentSize : dictSize;
4410 assert(!((dict) && (cdict))); /* either dict or cdict, not both */
4411 if ( (cdict)
4412 && (cdict->dictContentSize > 0)
4414 || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER
4416 || cdict->compressionLevel == 0)
4418 return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
4424 { size_t const dictID = cdict ?
4427 &cctx->ldmState, &cctx->workspace, &cctx->appliedParams, cdict->dictContent,
4428 cdict->dictContentSize, cdict->dictContentType, dtlm,
4446 const ZSTD_CDict* cdict,
4455 cdict,
4470 NULL /*cdict*/,
4660 size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict)
4662 if (cdict==NULL) return 0; /* support sizeof on NULL */
4663 DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict));
4664 /* cdict may be in the workspace */
4665 return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict))
4666 + ZSTD_cwksp_sizeof(&cdict->workspace);
4670 ZSTD_CDict* cdict,
4678 cdict->matchState.cParams = params.cParams;
4679 cdict->matchState.dedicatedDictSearch = params.enableDedicatedDictSearch;
4681 cdict->dictContent = dictBuffer;
4683 void *internalBuffer = ZSTD_cwksp_reserve_object(&cdict->workspace, ZSTD_cwksp_align(dictSize, sizeof(void*)));
4685 cdict->dictContent = internalBuffer;
4688 cdict->dictContentSize = dictSize;
4689 cdict->dictContentType = dictContentType;
4691 cdict->entropyWorkspace = (U32*)ZSTD_cwksp_reserve_object(&cdict->workspace, HUF_WORKSPACE_SIZE);
4695 ZSTD_reset_compressedBlockState(&cdict->cBlockState);
4697 &cdict->matchState,
4698 &cdict->workspace,
4710 &cdict->cBlockState, &cdict->matchState, NULL, &cdict->workspace,
4711 ¶ms, cdict->dictContent, cdict->dictContentSize,
4712 dictContentType, ZSTD_dtlm_full, cdict->entropyWorkspace);
4715 cdict->dictID = (U32)dictID;
4739 ZSTD_CDict* cdict;
4748 cdict = (ZSTD_CDict*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CDict));
4749 assert(cdict != NULL);
4750 ZSTD_cwksp_move(&cdict->workspace, &ws);
4751 cdict->customMem = customMem;
4752 cdict->compressionLevel = ZSTD_NO_CLEVEL; /* signals advanced API usage */
4753 cdict->useRowMatchFinder = useRowMatchFinder;
4754 return cdict;
4784 ZSTD_CDict* cdict;
4809 cdict = ZSTD_createCDict_advanced_internal(dictSize,
4814 if (ZSTD_isError( ZSTD_initCDict_internal(cdict,
4818 ZSTD_freeCDict(cdict);
4822 return cdict;
4828 ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
4831 if (cdict)
4832 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel;
4833 return cdict;
4839 ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dict, dictSize,
4842 if (cdict)
4843 cdict->compressionLevel = (compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : compressionLevel;
4844 return cdict;
4847 size_t ZSTD_freeCDict(ZSTD_CDict* cdict)
4849 if (cdict==NULL) return 0; /* support free on NULL */
4850 { ZSTD_customMem const cMem = cdict->customMem;
4851 int cdictInWorkspace = ZSTD_cwksp_owns_buffer(&cdict->workspace, cdict);
4852 ZSTD_cwksp_free(&cdict->workspace, cMem);
4854 ZSTD_customFree(cdict, cMem);
4888 ZSTD_CDict* cdict;
4896 cdict = (ZSTD_CDict*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CDict));
4897 if (cdict == NULL) return NULL;
4898 ZSTD_cwksp_move(&cdict->workspace, &ws);
4908 cdict->useRowMatchFinder = useRowMatchFinder;
4910 if (ZSTD_isError( ZSTD_initCDict_internal(cdict,
4916 return cdict;
4919 ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict)
4921 assert(cdict != NULL);
4922 return cdict->matchState.cParams;
4926 * Provides the dictID of the dictionary loaded into `cdict`.
4929 unsigned ZSTD_getDictID_fromCDict(const ZSTD_CDict* cdict)
4931 if (cdict==NULL) return 0;
4932 return cdict->dictID;
4939 ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict,
4944 RETURN_ERROR_IF(cdict==NULL, dictionary_wrong, "NULL pointer!");
4945 /* Initialize the cctxParams from the cdict */
4950 || pledgedSrcSize < cdict->dictContentSize * ZSTD_USE_CDICT_PARAMS_DICTSIZE_MULTIPLIER
4952 || cdict->compressionLevel == 0 ) ?
4953 ZSTD_getCParamsFromCDict(cdict)
4954 : ZSTD_getCParams(cdict->compressionLevel,
4956 cdict->dictContentSize);
4957 ZSTD_CCtxParams_init_internal(&cctxParams, ¶ms, cdict->compressionLevel);
4970 cdict,
4978 * cdict must be != NULL */
4980 ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict,
4983 return ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, pledgedSrcSize);
4987 * cdict must be != NULL */
4988 size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
4991 return ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, ZSTD_CONTENTSIZE_UNKNOWN);
5000 const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
5002 FORWARD_IF_ERROR(ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, srcSize), ""); /* will check if cdict != NULL */
5012 const ZSTD_CDict* cdict, ZSTD_frameParameters fParams)
5014 return ZSTD_compress_usingCDict_internal(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
5025 const ZSTD_CDict* cdict)
5028 return ZSTD_compress_usingCDict_internal(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
5069 static ZSTD_cParamMode_e ZSTD_getCParamMode(ZSTD_CDict const* cdict, ZSTD_CCtx_params const* params, U64 pledgedSrcSize)
5071 if (cdict != NULL && ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize))
5095 * Assumption 2 : either dict, or cdict, is defined, not both */
5097 const void* dict, size_t dictSize, const ZSTD_CDict* cdict,
5106 assert(!((dict) && (cdict))); /* either dict or cdict, not both */
5110 /* Dictionary is cleared if !cdict */
5111 FORWARD_IF_ERROR( ZSTD_CCtx_refCDict(zcs, cdict) , "");
5119 const ZSTD_CDict* cdict,
5127 FORWARD_IF_ERROR( ZSTD_CCtx_refCDict(zcs, cdict) , "");
5131 /* note : cdict must outlive compression session */
5132 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict)
5136 FORWARD_IF_ERROR( ZSTD_CCtx_refCDict(zcs, cdict) , "");
5431 assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */
5432 if (cctx->cdict && !cctx->localDict.cdict) {
5433 /* Let the cdict's compression level take priority over the requested params.
5434 * But do not take the cdict's compression level if the "cdict" is actually a localDict
5437 params.compressionLevel = cctx->cdict->compressionLevel;
5444 : (cctx->cdict ? cctx->cdict->dictContentSize : 0);
5445 ZSTD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, ¶ms, cctx->pledgedSrcSizePlusOne - 1);
5459 cctx->cdict,
5610 if (cctx->cdict) {
5611 dictSize = (U32)cctx->cdict->dictContentSize;
5676 if (cctx->cdict) {
5677 dictSize = cctx->cdict->dictContentSize;