summaryrefslogtreecommitdiff
path: root/vendor/github.com/klauspost/compress/flate/token.go
diff options
context:
space:
mode:
authordependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>2020-02-03 09:16:41 +0000
committerValentin Rothberg <rothberg@redhat.com>2020-02-03 13:51:31 +0100
commit94453c85c78908096764f8c0cb4cf72a470c182b (patch)
tree969f0921dedcdbc8c56a80e6679fbd70c3854aa4 /vendor/github.com/klauspost/compress/flate/token.go
parent4699d5e02d3270b5cc89f7528b53b823fbf88796 (diff)
downloadpodman-94453c85c78908096764f8c0cb4cf72a470c182b.tar.gz
podman-94453c85c78908096764f8c0cb4cf72a470c182b.tar.bz2
podman-94453c85c78908096764f8c0cb4cf72a470c182b.zip
build(deps): bump github.com/containers/storage from 1.15.7 to 1.15.8
Bumps [github.com/containers/storage](https://github.com/containers/storage) from 1.15.7 to 1.15.8. - [Release notes](https://github.com/containers/storage/releases) - [Changelog](https://github.com/containers/storage/blob/master/docs/containers-storage-changes.md) - [Commits](https://github.com/containers/storage/compare/v1.15.7...v1.15.8) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/klauspost/compress/flate/token.go')
-rw-r--r--vendor/github.com/klauspost/compress/flate/token.go42
1 files changed, 25 insertions, 17 deletions
diff --git a/vendor/github.com/klauspost/compress/flate/token.go b/vendor/github.com/klauspost/compress/flate/token.go
index b3df0d894..099c0ddbc 100644
--- a/vendor/github.com/klauspost/compress/flate/token.go
+++ b/vendor/github.com/klauspost/compress/flate/token.go
@@ -184,9 +184,7 @@ func (t *tokens) indexTokens(in []token) {
t.Reset()
for _, tok := range in {
if tok < matchType {
- t.tokens[t.n] = tok
- t.litHist[tok]++
- t.n++
+ t.AddLiteral(tok.literal())
continue
}
t.AddMatch(uint32(tok.length()), tok.offset())
@@ -211,43 +209,53 @@ func (t *tokens) AddLiteral(lit byte) {
t.nLits++
}
+// from https://stackoverflow.com/a/28730362
+func mFastLog2(val float32) float32 {
+ ux := int32(math.Float32bits(val))
+ log2 := (float32)(((ux >> 23) & 255) - 128)
+ ux &= -0x7f800001
+ ux += 127 << 23
+ uval := math.Float32frombits(uint32(ux))
+ log2 += ((-0.34484843)*uval+2.02466578)*uval - 0.67487759
+ return log2
+}
+
// EstimatedBits will return an minimum size estimated by an *optimal*
// compression of the block.
// The size of the block
func (t *tokens) EstimatedBits() int {
- shannon := float64(0)
+ shannon := float32(0)
bits := int(0)
nMatches := 0
if t.nLits > 0 {
- invTotal := 1.0 / float64(t.nLits)
+ invTotal := 1.0 / float32(t.nLits)
for _, v := range t.litHist[:] {
if v > 0 {
- n := float64(v)
- shannon += math.Ceil(-math.Log2(n*invTotal) * n)
+ n := float32(v)
+ shannon += -mFastLog2(n*invTotal) * n
}
}
// Just add 15 for EOB
shannon += 15
- for _, v := range t.extraHist[1 : literalCount-256] {
+ for i, v := range t.extraHist[1 : literalCount-256] {
if v > 0 {
- n := float64(v)
- shannon += math.Ceil(-math.Log2(n*invTotal) * n)
- bits += int(lengthExtraBits[v&31]) * int(v)
+ n := float32(v)
+ shannon += -mFastLog2(n*invTotal) * n
+ bits += int(lengthExtraBits[i&31]) * int(v)
nMatches += int(v)
}
}
}
if nMatches > 0 {
- invTotal := 1.0 / float64(nMatches)
- for _, v := range t.offHist[:offsetCodeCount] {
+ invTotal := 1.0 / float32(nMatches)
+ for i, v := range t.offHist[:offsetCodeCount] {
if v > 0 {
- n := float64(v)
- shannon += math.Ceil(-math.Log2(n*invTotal) * n)
- bits += int(offsetExtraBits[v&31]) * int(n)
+ n := float32(v)
+ shannon += -mFastLog2(n*invTotal) * n
+ bits += int(offsetExtraBits[i&31]) * int(v)
}
}
}
-
return int(shannon) + bits
}