From fbc3af2673224819e0a3a357f46d9c1e508c008a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 9 Jun 2013 19:48:30 +0200 Subject: [PATCH] rollsum: add OnSplitWithBits Change-Id: I6646695fdffbe8df697c54dab9a0601a0bf59459 --- pkg/rollsum/rollsum.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/rollsum/rollsum.go b/pkg/rollsum/rollsum.go index 4a66d7055..ca1eee681 100644 --- a/pkg/rollsum/rollsum.go +++ b/pkg/rollsum/rollsum.go @@ -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()