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

Method Encode

zstd/enc_best.go:78–466  ·  view source on GitHub ↗

Encode improves compression...

(blk *blockEnc, src []byte)

Source from the content-addressed store, hash-verified

76
77// Encode improves compression...
78func (e *bestFastEncoder) Encode(blk *blockEnc, src []byte) {
79 const (
80 // Input margin is the number of bytes we read (8)
81 // and the maximum we will read ahead (2)
82 inputMargin = 8 + 4
83 minNonLiteralBlockSize = 16
84 )
85
86 // Protect against e.cur wraparound.
87 for e.cur >= e.bufferReset-int32(len(e.hist)) {
88 if len(e.hist) == 0 {
89 e.table = [bestShortTableSize]prevEntry{}
90 e.longTable = [bestLongTableSize]prevEntry{}
91 e.cur = e.maxMatchOff
92 break
93 }
94 // Shift down everything in the table that isn't already too far away.
95 minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff
96 for i := range e.table[:] {
97 v := e.table[i].offset
98 v2 := e.table[i].prev
99 if v < minOff {
100 v = 0
101 v2 = 0
102 } else {
103 v = v - e.cur + e.maxMatchOff
104 if v2 < minOff {
105 v2 = 0
106 } else {
107 v2 = v2 - e.cur + e.maxMatchOff
108 }
109 }
110 e.table[i] = prevEntry{
111 offset: v,
112 prev: v2,
113 }
114 }
115 for i := range e.longTable[:] {
116 v := e.longTable[i].offset
117 v2 := e.longTable[i].prev
118 if v < minOff {
119 v = 0
120 v2 = 0
121 } else {
122 v = v - e.cur + e.maxMatchOff
123 if v2 < minOff {
124 v2 = 0
125 } else {
126 v2 = v2 - e.cur + e.maxMatchOff
127 }
128 }
129 e.longTable[i] = prevEntry{
130 offset: v,
131 prev: v2,
132 }
133 }
134 e.cur = e.maxMatchOff
135 break

Callers 1

EncodeNoHistMethod · 0.95

Calls 9

estBitsMethod · 0.95
ShannonEntropyBitsFunction · 0.92
printlnFunction · 0.85
matchLenFunction · 0.70
load6432Function · 0.70
hashLenFunction · 0.70
load3232Function · 0.70
addBlockMethod · 0.45
matchlenMethod · 0.45

Tested by

no test coverage detected