lib/scanner, vendor: Update github.com/chmduquesne/rollinghash (fixes #5334) (#5335)

Updates the package and fixes a test that depended on the old behavior
of Write() being equivalent to Reset()+Write() which is no longer the
case. The scanner already did resets after each block write, so this is
fine.
This commit is contained in:
Jakob Borg
2018-11-22 08:50:06 +01:00
committed by GitHub
parent d1704d5304
commit c0a26c918a
8 changed files with 172 additions and 107 deletions

View File

@@ -3,9 +3,11 @@ package main
import (
"flag"
"fmt"
"hash"
"io"
"log"
"os"
"runtime/pprof"
"time"
"code.cloudfoundry.org/bytefmt"
@@ -33,7 +35,10 @@ func genMasks() (res []uint64) {
return
}
func hash2uint64(s []byte) (res uint64) {
// Gets the hash sum as a uint64
func sum64(h hash.Hash) (res uint64) {
buf := make([]byte, 0, 8)
s := h.Sum(buf)
for _, b := range s {
res <<= 8
res |= uint64(b)
@@ -42,18 +47,27 @@ func hash2uint64(s []byte) (res uint64) {
}
func main() {
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
dostats := flag.Bool("stats", false, "Do some stats about the rolling sum")
size := flag.String("size", "256M", "How much data to read")
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
fileSize, err := bytefmt.ToBytes(*size)
if err != nil {
log.Fatal(err)
}
bufsize := 16 * MiB
rbuf := make([]byte, bufsize)
hbuf := make([]byte, 0, 8)
buf := make([]byte, bufsize)
t := time.Now()
f, err := os.Open("/dev/urandom")
@@ -66,10 +80,10 @@ func main() {
}
}()
io.ReadFull(f, rbuf)
io.ReadFull(f, buf)
roll := rollsum.New()
roll.Write(rbuf[:64])
roll.Write(buf[:64])
masks := genMasks()
hits := make(map[uint64]uint64)
@@ -97,15 +111,15 @@ func main() {
fmt.Printf(status)
fmt.Printf("\r")
}
_, err := io.ReadFull(f, rbuf)
_, err := io.ReadFull(f, buf)
if err != nil {
panic(err)
}
k = 0
}
roll.Roll(rbuf[k])
roll.Roll(buf[k])
if *dostats {
s := hash2uint64(roll.Sum(hbuf))
s := sum64(roll)
for _, m := range masks {
if s&m == m {
hits[m] += 1