MCPcopy
hub / github.com/klauspost/compress / Reset

Method Reset

zstd/enc_best.go:477–553  ·  view source on GitHub ↗

Reset will reset and set a dictionary if not nil

(d *dict, singleBlock bool)

Source from the content-addressed store, hash-verified

475
476// Reset will reset and set a dictionary if not nil
477func (e *bestFastEncoder) Reset(d *dict, singleBlock bool) {
478 e.resetBase(d, singleBlock)
479 if d == nil {
480 return
481 }
482 dictChanged := d != e.lastDict
483 // Init or copy dict table
484 if len(e.dictTable) != len(e.table) || dictChanged {
485 if len(e.dictTable) != len(e.table) {
486 e.dictTable = make([]prevEntry, len(e.table))
487 } else {
488 clear(e.dictTable)
489 }
490 end := int32(len(d.content)) - 8 + e.maxMatchOff
491 for i := e.maxMatchOff; i < end; i += 4 {
492 const hashLog = bestShortTableBits
493
494 cv := load6432(d.content, i-e.maxMatchOff)
495 nextHash := hashLen(cv, hashLog, bestShortLen) // 0 -> 4
496 nextHash1 := hashLen(cv>>8, hashLog, bestShortLen) // 1 -> 5
497 nextHash2 := hashLen(cv>>16, hashLog, bestShortLen) // 2 -> 6
498 nextHash3 := hashLen(cv>>24, hashLog, bestShortLen) // 3 -> 7
499 e.dictTable[nextHash] = prevEntry{
500 prev: e.dictTable[nextHash].offset,
501 offset: i,
502 }
503 e.dictTable[nextHash1] = prevEntry{
504 prev: e.dictTable[nextHash1].offset,
505 offset: i + 1,
506 }
507 e.dictTable[nextHash2] = prevEntry{
508 prev: e.dictTable[nextHash2].offset,
509 offset: i + 2,
510 }
511 e.dictTable[nextHash3] = prevEntry{
512 prev: e.dictTable[nextHash3].offset,
513 offset: i + 3,
514 }
515 }
516 }
517
518 // Init or copy dict long table
519 if len(e.dictLongTable) != len(e.longTable) || dictChanged {
520 if len(e.dictLongTable) != len(e.longTable) {
521 e.dictLongTable = make([]prevEntry, len(e.longTable))
522 } else {
523 clear(e.dictLongTable)
524 }
525 if len(d.content) >= 8 {
526 cv := load6432(d.content, 0)
527 h := hashLen(cv, bestLongTableBits, bestLongLen)
528 e.dictLongTable[h] = prevEntry{
529 offset: e.maxMatchOff,
530 prev: e.dictLongTable[h].offset,
531 }
532
533 end := int32(len(d.content)) - 8 + e.maxMatchOff
534 off := 8 // First to read

Callers

nothing calls this directly

Calls 3

resetBaseMethod · 0.80
load6432Function · 0.70
hashLenFunction · 0.70

Tested by

no test coverage detected