| |
| |
| |
|
|
| package flate |
|
|
| const ( |
| |
| |
| |
| lengthShift = 22 |
| offsetMask = 1<<lengthShift - 1 |
| typeMask = 3 << 30 |
| literalType = 0 << 30 |
| matchType = 1 << 30 |
| ) |
|
|
| |
| |
| var lengthCodes = [...]uint32{ |
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, |
| 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, |
| 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, |
| 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, |
| 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, |
| 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, |
| 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, |
| 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, |
| 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, |
| 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, |
| 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, |
| 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, |
| 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, |
| 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
| 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
| 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
| 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
| 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
| 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
| 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, |
| 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
| 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
| 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, |
| 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
| 27, 27, 27, 27, 27, 28, |
| } |
|
|
| var offsetCodes = [...]uint32{ |
| 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, |
| 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, |
| 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
| 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
| 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
| 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
| 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
| 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
| 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
| 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
| } |
|
|
| type token uint32 |
|
|
| |
| func literalToken(literal uint32) token { return token(literalType + literal) } |
|
|
| |
| func matchToken(xlength uint32, xoffset uint32) token { |
| return token(matchType + xlength<<lengthShift + xoffset) |
| } |
|
|
| |
| func (t token) literal() uint32 { return uint32(t - literalType) } |
|
|
| |
| func (t token) offset() uint32 { return uint32(t) & offsetMask } |
|
|
| func (t token) length() uint32 { return uint32((t - matchType) >> lengthShift) } |
|
|
| func lengthCode(len uint32) uint32 { return lengthCodes[len] } |
|
|
| |
| func offsetCode(off uint32) uint32 { |
| if off < uint32(len(offsetCodes)) { |
| return offsetCodes[off] |
| } |
| if off>>7 < uint32(len(offsetCodes)) { |
| return offsetCodes[off>>7] + 14 |
| } |
| return offsetCodes[off>>14] + 28 |
| } |
|
|