mirror of https://github.com/perkeep/perkeep.git
internal/rollsum: replace with go4.org/rollsum
Fixes #1253 Change-Id: I64aac5739a18d2e19494881dcceff9d43355fac2
This commit is contained in:
parent
0683145d61
commit
2a85cb7142
|
@ -24,7 +24,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"perkeep.org/internal/rollsum"
|
||||
"go4.org/rollsum"
|
||||
)
|
||||
|
||||
type span struct {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -51,7 +51,7 @@ require (
|
|||
github.com/syndtr/goleveldb v0.0.0-20180608030153-db3ee9ee8931
|
||||
github.com/tgulacsi/picago v0.0.0-20171229130838-9e1ac2306c70
|
||||
github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443
|
||||
go4.org v0.0.0-20180413184151-a2a47940e6bc
|
||||
go4.org v0.0.0-20190218023631-ce4c26f7be8e
|
||||
golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb
|
||||
golang.org/x/image v0.0.0-20171214225156-12117c17ca67
|
||||
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce
|
||||
|
|
4
go.sum
4
go.sum
|
@ -109,6 +109,8 @@ github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443 h1:ovXpn6PhLk
|
|||
github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE=
|
||||
go4.org v0.0.0-20180413184151-a2a47940e6bc h1:poolp8Py6LYswolW85K75U8L42AkHWBv/+ewlI/ZHA0=
|
||||
go4.org v0.0.0-20180413184151-a2a47940e6bc/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
|
||||
go4.org v0.0.0-20190218023631-ce4c26f7be8e h1:m9LfARr2VIOW0vsV19kEKp/sWQvZnGobA8JHui/XJoY=
|
||||
go4.org v0.0.0-20190218023631-ce4c26f7be8e/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
|
||||
golang.org/x/crypto v0.0.0-20180606015541-b47b15873692 h1:O9W34I8ef1ifsNUjJoqTsouE17HSL5RVJNn9pLMf7Og=
|
||||
golang.org/x/crypto v0.0.0-20180606015541-b47b15873692/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb h1:Ah9YqXLj6fEgeKqcmBuLCbAsrF3ScD7dJ/bYM0C6tXI=
|
||||
|
@ -142,7 +144,7 @@ gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 h1:/saqWwm73dLmuzbNhe92F0QsZ/
|
|||
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||
honnef.co/go/js/dom v0.0.0-20160310112645-24aa052bc5c6 h1:tt1qVqcZt6cRcvoUTMBbCnLEkjm2o4WGMkF0mE9Fx3s=
|
||||
honnef.co/go/js/dom v0.0.0-20160310112645-24aa052bc5c6/go.mod h1:sUMDUKNB2ZcVjt92UnLy3cdGs+wDAcrPdV3JP6sVgA4=
|
||||
myitcv.io v0.0.0-20180717150903-bf2c84553c78 h1:Hc0gqDZHlmLo4xohfx/0/azkaztHW1CAFSXa4ygFoqI=
|
||||
myitcv.io v0.0.0-20180717150903-bf2c84553c78 h1:ISoxJY6pqBP0HmQEwjNldhzlyfZAswY0yTjZZRfGYXk=
|
||||
myitcv.io v0.0.0-20180717150903-bf2c84553c78/go.mod h1:eZGravSD0Y1vesgGXvhvceVMg34vGeRCYvzHtT9nX1k=
|
||||
rsc.io/pdf v0.0.0-20170302045715-1d34785eb915 h1:Deg3CmTFQ+bWVBNEjlhrfNsSl2/YI20/XNKCxBX5aVg=
|
||||
rsc.io/pdf v0.0.0-20170302045715-1d34785eb915/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
|
|
|
@ -37,7 +37,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"perkeep.org/internal/rollsum"
|
||||
"go4.org/rollsum"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"perkeep.org/internal/rollsum"
|
||||
"go4.org/rollsum"
|
||||
"perkeep.org/pkg/blob"
|
||||
"perkeep.org/pkg/blobserver"
|
||||
|
||||
|
|
|
@ -19,7 +19,11 @@ limitations under the License.
|
|||
//
|
||||
// The bup project is at https://github.com/apenwarr/bup and its splitting in
|
||||
// particular is at https://github.com/apenwarr/bup/blob/master/lib/bup/bupsplit.c
|
||||
package rollsum // import "perkeep.org/internal/rollsum"
|
||||
package rollsum // import "go4.org/rollsum"
|
||||
|
||||
import (
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
const windowSize = 64 // Roll assumes windowSize is a power of 2
|
||||
const charOffset = 31
|
||||
|
@ -46,6 +50,7 @@ func (rs *RollSum) add(drop, add uint32) {
|
|||
rs.s2 += s1 - uint32(windowSize)*(drop+charOffset)
|
||||
}
|
||||
|
||||
// Roll adds ch to the rolling sum.
|
||||
func (rs *RollSum) Roll(ch byte) {
|
||||
wp := &rs.window[rs.wofs]
|
||||
rs.add(uint32(*wp), uint32(ch))
|
||||
|
@ -53,13 +58,13 @@ func (rs *RollSum) Roll(ch byte) {
|
|||
rs.wofs = (rs.wofs + 1) & (windowSize - 1)
|
||||
}
|
||||
|
||||
// OnSplit returns whether at least 13 consecutive trailing bits of
|
||||
// OnSplit reports 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))
|
||||
}
|
||||
|
||||
// OnSplitWithBits returns whether at least n consecutive trailing bits
|
||||
// OnSplitWithBits reports 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
|
||||
|
@ -67,13 +72,8 @@ func (rs *RollSum) OnSplitWithBits(n uint32) bool {
|
|||
}
|
||||
|
||||
func (rs *RollSum) Bits() int {
|
||||
bits := blobBits
|
||||
rsum := rs.Digest()
|
||||
rsum >>= blobBits
|
||||
for ; (rsum>>1)&1 != 0; bits++ {
|
||||
rsum >>= 1
|
||||
}
|
||||
return bits
|
||||
rsum := rs.Digest() >> (blobBits + 1)
|
||||
return blobBits + bits.TrailingZeros32(^rsum)
|
||||
}
|
||||
|
||||
func (rs *RollSum) Digest() uint32 {
|
Loading…
Reference in New Issue