From 50550a14addea833aef2fe2a4137cb3195ee2b2e Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Thu, 11 Jun 2020 18:27:07 -0700 Subject: [PATCH] adding dedicated dict load method to lazy --- lib/compress/zstd_lazy.c | 19 +++++++++++++++++++ lib/compress/zstd_lazy.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index 6371863f..b1171f14 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -475,6 +475,25 @@ U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip) { return ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, ms->cParams.minMatch); } +void ZSTD_lazy_loadDictionary(ZSTD_matchState_t* ms, const BYTE* const ip) +{ + U32 const target = (U32)(ip - ms->window.base); + U32* const chainTable = ms->chainTable; + U32 const chainMask = (1 << ms->cParams.chainLog) - 1; + for (U32 idx = ms->nextToUpdate; idx < target; idx++) { + U32 const h = ZSTD_hashPtr( + ms->window.base + idx, + ms->cParams.hashLog - DD_BLOG, + ms->cParams.minMatch) << DD_BLOG; + chainTable[idx & chainMask] = ms->hashTable[h]; + ms->hashTable[h] = idx; + /* Same logic as before. But now, just copy the into bucket */ + for (U32 i = 0; i < (1 << DD_BLOG); i++) + ms->hashTable[h + i] = chainTable[ms->hashTable[h + i] & chainMask]; + } + ms->nextToUpdate = target; +} + /* inlining is important to hardwire a hot branch (template emulation) */ FORCE_INLINE_TEMPLATE diff --git a/lib/compress/zstd_lazy.h b/lib/compress/zstd_lazy.h index 581936f0..74e9368e 100644 --- a/lib/compress/zstd_lazy.h +++ b/lib/compress/zstd_lazy.h @@ -19,6 +19,8 @@ extern "C" { U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip); +void ZSTD_lazy_loadDictionary(ZSTD_matchState_t* ms, const BYTE* const ip); + void ZSTD_preserveUnsortedMark (U32* const table, U32 const size, U32 const reducerValue); /*! used in ZSTD_reduceIndex(). preemptively increase value of ZSTD_DUBT_UNSORTED_MARK */ size_t ZSTD_compressBlock_btlazy2(