mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-06 00:57:19 -04:00
LZX: Improve huffman table encoding
This commit is contained in:
+5
-5
@@ -17,6 +17,8 @@ const (
|
|||||||
maincodecount = 496
|
maincodecount = 496
|
||||||
maincodesplit = 256
|
maincodesplit = 256
|
||||||
lencodecount = 249
|
lencodecount = 249
|
||||||
|
lenshift = 9
|
||||||
|
codemask = 0x1ff
|
||||||
|
|
||||||
maxBlockSize = 32768
|
maxBlockSize = 32768
|
||||||
windowSize = 32768
|
windowSize = 32768
|
||||||
@@ -109,7 +111,6 @@ func (f *decompressor) getBits(n byte) uint16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type huffman struct {
|
type huffman struct {
|
||||||
lens []byte
|
|
||||||
table []uint16
|
table []uint16
|
||||||
maxbits byte
|
maxbits byte
|
||||||
}
|
}
|
||||||
@@ -157,14 +158,13 @@ func buildTable(codelens []byte) *huffman {
|
|||||||
code := first[cl]
|
code := first[cl]
|
||||||
extendedCode := code << (max - cl)
|
extendedCode := code << (max - cl)
|
||||||
for j := uint(0); j < 1<<(max-cl); j++ {
|
for j := uint(0); j < 1<<(max-cl); j++ {
|
||||||
table[extendedCode+j] = uint16(i)
|
table[extendedCode+j] = uint16(cl)<<lenshift | uint16(i)
|
||||||
}
|
}
|
||||||
first[cl]++
|
first[cl]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &huffman{
|
return &huffman{
|
||||||
lens: codelens,
|
|
||||||
table: table,
|
table: table,
|
||||||
maxbits: max,
|
maxbits: max,
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ func (f *decompressor) getCode(h *huffman) uint16 {
|
|||||||
// are, since entries with all possible suffixes were
|
// are, since entries with all possible suffixes were
|
||||||
// added to the table.
|
// added to the table.
|
||||||
c := h.table[f.c>>(32-h.maxbits)]
|
c := h.table[f.c>>(32-h.maxbits)]
|
||||||
n := h.lens[c]
|
n := byte(c >> lenshift)
|
||||||
if f.nbits < n {
|
if f.nbits < n {
|
||||||
f.err = io.ErrUnexpectedEOF
|
f.err = io.ErrUnexpectedEOF
|
||||||
return 0
|
return 0
|
||||||
@@ -195,7 +195,7 @@ func (f *decompressor) getCode(h *huffman) uint16 {
|
|||||||
// code length.
|
// code length.
|
||||||
f.c <<= n
|
f.c <<= n
|
||||||
f.nbits -= n
|
f.nbits -= n
|
||||||
return c
|
return c & codemask
|
||||||
}
|
}
|
||||||
|
|
||||||
// mod17 computes the value mod 17.
|
// mod17 computes the value mod 17.
|
||||||
|
|||||||
Reference in New Issue
Block a user