Upgrade github.com/klauspost/compress from v1.11.13 to v1.15.9
The package has multiple improvements and bug fixes. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
		
							
								
								
									
										75
									
								
								vendor/github.com/klauspost/compress/huff0/compress.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										75
									
								
								vendor/github.com/klauspost/compress/huff0/compress.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -2,6 +2,7 @@ package huff0
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"math"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
@@ -161,6 +162,70 @@ func compress(in []byte, s *Scratch, compressor func(src []byte) ([]byte, error)
 | 
			
		||||
	return s.Out, false, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EstimateSizes will estimate the data sizes
 | 
			
		||||
func EstimateSizes(in []byte, s *Scratch) (tableSz, dataSz, reuseSz int, err error) {
 | 
			
		||||
	s, err = s.prepare(in)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, 0, 0, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Create histogram, if none was provided.
 | 
			
		||||
	tableSz, dataSz, reuseSz = -1, -1, -1
 | 
			
		||||
	maxCount := s.maxCount
 | 
			
		||||
	var canReuse = false
 | 
			
		||||
	if maxCount == 0 {
 | 
			
		||||
		maxCount, canReuse = s.countSimple(in)
 | 
			
		||||
	} else {
 | 
			
		||||
		canReuse = s.canUseTable(s.prevTable)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// We want the output size to be less than this:
 | 
			
		||||
	wantSize := len(in)
 | 
			
		||||
	if s.WantLogLess > 0 {
 | 
			
		||||
		wantSize -= wantSize >> s.WantLogLess
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Reset for next run.
 | 
			
		||||
	s.clearCount = true
 | 
			
		||||
	s.maxCount = 0
 | 
			
		||||
	if maxCount >= len(in) {
 | 
			
		||||
		if maxCount > len(in) {
 | 
			
		||||
			return 0, 0, 0, fmt.Errorf("maxCount (%d) > length (%d)", maxCount, len(in))
 | 
			
		||||
		}
 | 
			
		||||
		if len(in) == 1 {
 | 
			
		||||
			return 0, 0, 0, ErrIncompressible
 | 
			
		||||
		}
 | 
			
		||||
		// One symbol, use RLE
 | 
			
		||||
		return 0, 0, 0, ErrUseRLE
 | 
			
		||||
	}
 | 
			
		||||
	if maxCount == 1 || maxCount < (len(in)>>7) {
 | 
			
		||||
		// Each symbol present maximum once or too well distributed.
 | 
			
		||||
		return 0, 0, 0, ErrIncompressible
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Calculate new table.
 | 
			
		||||
	err = s.buildCTable()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, 0, 0, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if false && !s.canUseTable(s.cTable) {
 | 
			
		||||
		panic("invalid table generated")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tableSz, err = s.cTable.estTableSize(s)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, 0, 0, err
 | 
			
		||||
	}
 | 
			
		||||
	if canReuse {
 | 
			
		||||
		reuseSz = s.prevTable.estimateSize(s.count[:s.symbolLen])
 | 
			
		||||
	}
 | 
			
		||||
	dataSz = s.cTable.estimateSize(s.count[:s.symbolLen])
 | 
			
		||||
 | 
			
		||||
	// Restore
 | 
			
		||||
	return tableSz, dataSz, reuseSz, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *Scratch) compress1X(src []byte) ([]byte, error) {
 | 
			
		||||
	return s.compress1xDo(s.Out, src)
 | 
			
		||||
}
 | 
			
		||||
@@ -225,6 +290,10 @@ func (s *Scratch) compress4X(src []byte) ([]byte, error) {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		if len(s.Out)-idx > math.MaxUint16 {
 | 
			
		||||
			// We cannot store the size in the jump table
 | 
			
		||||
			return nil, ErrIncompressible
 | 
			
		||||
		}
 | 
			
		||||
		// Write compressed length as little endian before block.
 | 
			
		||||
		if i < 3 {
 | 
			
		||||
			// Last length is not written.
 | 
			
		||||
@@ -268,6 +337,10 @@ func (s *Scratch) compress4Xp(src []byte) ([]byte, error) {
 | 
			
		||||
			return nil, errs[i]
 | 
			
		||||
		}
 | 
			
		||||
		o := s.tmpOut[i]
 | 
			
		||||
		if len(o) > math.MaxUint16 {
 | 
			
		||||
			// We cannot store the size in the jump table
 | 
			
		||||
			return nil, ErrIncompressible
 | 
			
		||||
		}
 | 
			
		||||
		// Write compressed length as little endian before block.
 | 
			
		||||
		if i < 3 {
 | 
			
		||||
			// Last length is not written.
 | 
			
		||||
@@ -331,6 +404,7 @@ func (s *Scratch) canUseTable(c cTable) bool {
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//lint:ignore U1000 used for debugging
 | 
			
		||||
func (s *Scratch) validateTable(c cTable) bool {
 | 
			
		||||
	if len(c) < int(s.symbolLen) {
 | 
			
		||||
		return false
 | 
			
		||||
@@ -536,7 +610,6 @@ func (s *Scratch) huffSort() {
 | 
			
		||||
		}
 | 
			
		||||
		nodes[pos&huffNodesMask] = nodeElt{count: c, symbol: byte(n)}
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *Scratch) setMaxHeight(lastNonNull int) uint8 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user