mirror of
https://github.com/kopia/kopia.git
synced 2026-05-07 14:26:51 -04:00
splitter: exposed MaxSegmentSize() for splitters
This commit is contained in:
committed by
Julio López
parent
4564ed5ac1
commit
b1020941dd
@@ -13,6 +13,7 @@
|
||||
// It must return true if the object should be split after byte b is processed.
|
||||
type Splitter interface {
|
||||
ShouldSplit(b byte) bool
|
||||
MaxSegmentSize() int
|
||||
Reset()
|
||||
Close()
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ func (rs *buzhash32Splitter) ShouldSplit(b byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (rs *buzhash32Splitter) MaxSegmentSize() int {
|
||||
return rs.maxSize
|
||||
}
|
||||
|
||||
func newBuzHash32SplitterFactory(avgSize int) Factory {
|
||||
// avgSize must be a power of two, so 0b000001000...0000
|
||||
// it just so happens that mask is avgSize-1 :)
|
||||
|
||||
@@ -23,6 +23,10 @@ func (s *fixedSplitter) ShouldSplit(b byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *fixedSplitter) MaxSegmentSize() int {
|
||||
return s.chunkLength
|
||||
}
|
||||
|
||||
// Fixed returns a factory that creates splitters with fixed chunk length.
|
||||
func Fixed(length int) Factory {
|
||||
return func() Splitter {
|
||||
|
||||
@@ -39,6 +39,10 @@ func (rs *rabinKarp64Splitter) ShouldSplit(b byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (rs *rabinKarp64Splitter) MaxSegmentSize() int {
|
||||
return rs.maxSize
|
||||
}
|
||||
|
||||
func newRabinKarp64SplitterFactory(avgSize int) Factory {
|
||||
mask := uint64(avgSize - 1)
|
||||
minSize, maxSize := avgSize/2, avgSize*2 //nolint:gomnd
|
||||
|
||||
@@ -69,6 +69,10 @@ func TestSplitterStability(t *testing.T) {
|
||||
minSplit := int(math.MaxInt32)
|
||||
count := 0
|
||||
|
||||
if got, want := s.MaxSegmentSize(), tc.maxSplit; got != want {
|
||||
t.Errorf("unexpected max segment size: %v, want %v", got, want)
|
||||
}
|
||||
|
||||
for i, p := range rnd {
|
||||
if !s.ShouldSplit(p) {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user