rollsum: add OnSplitWithBits

Change-Id: I6646695fdffbe8df697c54dab9a0601a0bf59459
This commit is contained in:
Brad Fitzpatrick 2013-06-09 19:48:30 +02:00
parent 70afe9597a
commit fbc3af2673
1 changed files with 9 additions and 0 deletions

View File

@ -53,10 +53,19 @@ func (rs *RollSum) Roll(ch byte) {
rs.wofs = (rs.wofs + 1) % windowSize
}
// OnSplit returns whether at least 13 consecutive trailing bits of
// the current checksum are set the same way.
func (rs *RollSum) OnSplit() bool {
return (rs.s2 & (blobSize - 1)) == ((^0) & (blobSize - 1))
}
// OnSplit returns whether at least n consecutive trailing bits
// of the current checksum are set the same way.
func (rs *RollSum) OnSplitWithBits(n uint32) bool {
mask := (uint32(1) << n) - 1
return rs.s2 & mask == (^uint32(0)) & mask
}
func (rs *RollSum) Bits() int {
bits := blobBits
rsum := rs.Digest()