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

Method readNCount

zstd/fse_decoder.go:52–184  ·  view source on GitHub ↗

readNCount will read the symbol distribution so decoding tables can be constructed.

(b *byteReader, maxSymbol uint16)

Source from the content-addressed store, hash-verified

50
51// readNCount will read the symbol distribution so decoding tables can be constructed.
52func (s *fseDecoder) readNCount(b *byteReader, maxSymbol uint16) error {
53 var (
54 charnum uint16
55 previous0 bool
56 )
57 if b.remain() < 4 {
58 return errors.New("input too small")
59 }
60 bitStream := b.Uint32NC()
61 nbBits := uint((bitStream & 0xF) + minTablelog) // extract tableLog
62 if nbBits > tablelogAbsoluteMax {
63 println("Invalid tablelog:", nbBits)
64 return errors.New("tableLog too large")
65 }
66 bitStream >>= 4
67 bitCount := uint(4)
68
69 s.actualTableLog = uint8(nbBits)
70 remaining := int32((1 << nbBits) + 1)
71 threshold := int32(1 << nbBits)
72 gotTotal := int32(0)
73 nbBits++
74
75 for remaining > 1 && charnum <= maxSymbol {
76 if previous0 {
77 //println("prev0")
78 n0 := charnum
79 for (bitStream & 0xFFFF) == 0xFFFF {
80 //println("24 x 0")
81 n0 += 24
82 if r := b.remain(); r > 5 {
83 b.advance(2)
84 // The check above should make sure we can read 32 bits
85 bitStream = b.Uint32NC() >> bitCount
86 } else {
87 // end of bit stream
88 bitStream >>= 16
89 bitCount += 16
90 }
91 }
92 //printf("bitstream: %d, 0b%b", bitStream&3, bitStream)
93 for (bitStream & 3) == 3 {
94 n0 += 3
95 bitStream >>= 2
96 bitCount += 2
97 }
98 n0 += uint16(bitStream & 3)
99 bitCount += 2
100
101 if n0 > maxSymbolValue {
102 return errors.New("maxSymbolValue too small")
103 }
104 //println("inserting ", n0-charnum, "zeroes from idx", charnum, "ending before", n0)
105 for charnum < n0 {
106 s.norm[uint8(charnum)] = 0
107 charnum++
108 }
109

Callers 2

prepareSequencesMethod · 0.45
loadDictFunction · 0.45

Calls 6

buildDtableMethod · 0.95
printlnFunction · 0.85
Uint32NCMethod · 0.80
remainMethod · 0.45
advanceMethod · 0.45
Uint32Method · 0.45

Tested by

no test coverage detected