From 3462ca0e8e2089faab781d514cbbf1a86a0f3f92 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 19 Nov 2025 08:00:00 +0800 Subject: Import flate --- internal/flate/token.go | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 internal/flate/token.go (limited to 'internal/flate/token.go') diff --git a/internal/flate/token.go b/internal/flate/token.go new file mode 100644 index 00000000..fc0e4941 --- /dev/null +++ b/internal/flate/token.go @@ -0,0 +1,97 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package flate + +const ( + // 2 bits: type 0 = literal 1=EOF 2=Match 3=Unused + // 8 bits: xlength = length - MIN_MATCH_LENGTH + // 22 bits xoffset = offset - MIN_OFFSET_SIZE, or literal + lengthShift = 22 + offsetMask = 1< pair into a match token. +func matchToken(xlength uint32, xoffset uint32) token { + return token(matchType + xlength<> lengthShift) } + +func lengthCode(len uint32) uint32 { return lengthCodes[len] } + +// Returns the offset code corresponding to a specific offset. +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 +} -- cgit v1.3.1-10-gc9f91