Encode mimmics functionality in zstd_dfast.c
(blk *blockEnc, src []byte)
| 36 | |
| 37 | // Encode mimmics functionality in zstd_dfast.c |
| 38 | func (e *doubleFastEncoder) Encode(blk *blockEnc, src []byte) { |
| 39 | const ( |
| 40 | // Input margin is the number of bytes we read (8) |
| 41 | // and the maximum we will read ahead (2) |
| 42 | inputMargin = 8 + 2 |
| 43 | minNonLiteralBlockSize = 16 |
| 44 | ) |
| 45 | |
| 46 | // Protect against e.cur wraparound. |
| 47 | for e.cur >= e.bufferReset-int32(len(e.hist)) { |
| 48 | if len(e.hist) == 0 { |
| 49 | e.table = [dFastShortTableSize]tableEntry{} |
| 50 | e.longTable = [dFastLongTableSize]tableEntry{} |
| 51 | e.cur = e.maxMatchOff |
| 52 | break |
| 53 | } |
| 54 | // Shift down everything in the table that isn't already too far away. |
| 55 | minOff := e.cur + int32(len(e.hist)) - e.maxMatchOff |
| 56 | for i := range e.table[:] { |
| 57 | v := e.table[i].offset |
| 58 | if v < minOff { |
| 59 | v = 0 |
| 60 | } else { |
| 61 | v = v - e.cur + e.maxMatchOff |
| 62 | } |
| 63 | e.table[i].offset = v |
| 64 | } |
| 65 | for i := range e.longTable[:] { |
| 66 | v := e.longTable[i].offset |
| 67 | if v < minOff { |
| 68 | v = 0 |
| 69 | } else { |
| 70 | v = v - e.cur + e.maxMatchOff |
| 71 | } |
| 72 | e.longTable[i].offset = v |
| 73 | } |
| 74 | e.cur = e.maxMatchOff |
| 75 | break |
| 76 | } |
| 77 | |
| 78 | s := e.addBlock(src) |
| 79 | blk.size = len(src) |
| 80 | if len(src) < minNonLiteralBlockSize { |
| 81 | blk.extraLits = len(src) |
| 82 | blk.literals = blk.literals[:len(src)] |
| 83 | copy(blk.literals, src) |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | // Override src |
| 88 | src = e.hist |
| 89 | sLimit := int32(len(src)) - inputMargin |
| 90 | // stepSize is the number of bytes to skip on every main loop iteration. |
| 91 | // It should be >= 1. |
| 92 | const stepSize = 1 |
| 93 | |
| 94 | const kSearchStrength = 8 |
| 95 |