函数源码 |
Source File:lib\zstd\compress.c |
Create Date:2022-07-27 08:00:34 |
首页 | Copyright©Brick |
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | /*! ZSTD_resetCCtx_advanced() : note : `params` must be validated */ static size_t ZSTD_resetCCtx_advanced(ZSTD_CCtx *zc, ZSTD_parameters params, U64 frameContentSize, ZSTD_compResetPolicy_e const crp) { if (crp == ZSTDcrp_continue) if (ZSTD_equivalentParams(params, zc->params)) { zc->flagStaticTables = 0; zc->flagStaticHufTable = HUF_repeat_none; return ZSTD_continueCCtx(zc, params, frameContentSize); } { size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, ( size_t )1 << params.cParams.windowLog); U32 const divider = (params.cParams.searchLength == 3) ? 3 : 4; size_t const maxNbSeq = blockSize / divider; size_t const tokenSpace = blockSize + 11 * maxNbSeq; size_t const chainSize = (params.cParams.strategy == ZSTD_fast) ? 0 : (1 << params.cParams.chainLog); size_t const hSize = (( size_t )1) << params.cParams.hashLog; U32 const hashLog3 = (params.cParams.searchLength > 3) ? 0 : MIN(ZSTD_HASHLOG3_MAX, params.cParams.windowLog); size_t const h3Size = (( size_t )1) << hashLog3; size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof (U32); void *ptr; /* Check if workSpace is large enough, alloc a new one if needed */ { size_t const optSpace = ((MaxML + 1) + (MaxLL + 1) + (MaxOff + 1) + (1 << Litbits)) * sizeof (U32) + (ZSTD_OPT_NUM + 1) * ( sizeof (ZSTD_match_t) + sizeof (ZSTD_optimal_t)); size_t const neededSpace = tableSpace + (256 * sizeof (U32)) /* huffTable */ + tokenSpace + (((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btopt2)) ? optSpace : 0); if (zc->workSpaceSize < neededSpace) { ZSTD_free(zc->workSpace, zc->customMem); zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem); if (zc->workSpace == NULL) return ERROR(memory_allocation); zc->workSpaceSize = neededSpace; } } if (crp != ZSTDcrp_noMemset) memset (zc->workSpace, 0, tableSpace); /* reset tables only */ xxh64_reset(&zc->xxhState, 0); zc->hashLog3 = hashLog3; zc->hashTable = (U32 *)(zc->workSpace); zc->chainTable = zc->hashTable + hSize; zc->hashTable3 = zc->chainTable + chainSize; ptr = zc->hashTable3 + h3Size; zc->hufTable = (HUF_CElt *)ptr; zc->flagStaticTables = 0; zc->flagStaticHufTable = HUF_repeat_none; ptr = ((U32 *)ptr) + 256; /* note : HUF_CElt* is incomplete type, size is simulated using U32 */ zc->nextToUpdate = 1; zc->nextSrc = NULL; zc->base = NULL; zc->dictBase = NULL; zc->dictLimit = 0; zc->lowLimit = 0; zc->params = params; zc->blockSize = blockSize; zc->frameContentSize = frameContentSize; { int i; for (i = 0; i < ZSTD_REP_NUM; i++) zc->rep[i] = repStartValue[i]; } if ((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btopt2)) { zc->seqStore.litFreq = (U32 *)ptr; zc->seqStore.litLengthFreq = zc->seqStore.litFreq + (1 << Litbits); zc->seqStore.matchLengthFreq = zc->seqStore.litLengthFreq + (MaxLL + 1); zc->seqStore.offCodeFreq = zc->seqStore.matchLengthFreq + (MaxML + 1); ptr = zc->seqStore.offCodeFreq + (MaxOff + 1); zc->seqStore.matchTable = (ZSTD_match_t *)ptr; ptr = zc->seqStore.matchTable + ZSTD_OPT_NUM + 1; zc->seqStore.priceTable = (ZSTD_optimal_t *)ptr; ptr = zc->seqStore.priceTable + ZSTD_OPT_NUM + 1; zc->seqStore.litLengthSum = 0; } zc->seqStore.sequencesStart = (seqDef *)ptr; ptr = zc->seqStore.sequencesStart + maxNbSeq; zc->seqStore.llCode = ( BYTE *)ptr; zc->seqStore.mlCode = zc->seqStore.llCode + maxNbSeq; zc->seqStore.ofCode = zc->seqStore.mlCode + maxNbSeq; zc->seqStore.litStart = zc->seqStore.ofCode + maxNbSeq; zc->stage = ZSTDcs_init; zc->dictID = 0; zc->loadedDictEnd = 0; return 0; } } |