This file is indexed.

/usr/share/gocode/src/github.com/chmduquesne/rollinghash/buzhash64/buzhash64_test.go is in golang-github-chmduquesne-rollinghash-dev 2.0.2+git20170321.9.043b8fd-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
package buzhash64_test

import (
	"hash"
	"math/rand"
	"testing"
	"time"

	"github.com/chmduquesne/rollinghash"
	rollsum "github.com/chmduquesne/rollinghash/buzhash64"
)

var testHash [256]uint64

func RandomHash() (res [256]uint64) {
	used := make(map[uint64]bool)
	for i, _ := range res {
		x := uint64(rand.Int63())
		for used[x] {
			x = uint64(rand.Int63())
		}
		used[x] = true
		res[i] = x
	}
	return res
}

func init() {
	rand.Seed(time.Now().UTC().UnixNano())
	testHash = RandomHash()
}

func NewRollingHash() rollinghash.Hash64 {
	return rollsum.NewFromUint64Array(testHash)
}

// This is a no-op to prove that we implement hash.Hash64
var _ = hash.Hash64(rollsum.New())

func Sum32ByWriteAndRoll(b []byte) uint64 {
	q := []byte(" ")
	q = append(q, b...)
	roll := NewRollingHash()
	roll.Write(q[:len(q)-1])
	roll.Roll(q[len(q)-1])
	return roll.Sum64()
}

func Sum32ByWriteOnly(b []byte) uint64 {
	roll := NewRollingHash()
	roll.Write(b)
	return roll.Sum64()
}

func RandomBytes() (res []byte) {
	n := rand.Intn(8192)
	res = make([]byte, n)
	rand.Read(res)
	return res
}

func TestBlackBox(t *testing.T) {
	for i := 0; i < 1000; i++ {
		in := RandomBytes()
		if len(in) > 0 {
			sum := Sum32ByWriteAndRoll(in)
			ref := Sum32ByWriteOnly(in)

			if ref != sum {
				t.Errorf("Expected 0x%x, got 0x%x", ref, sum)
			}
		}
	}
}

func BenchmarkRollingKB(b *testing.B) {
	b.SetBytes(1024)
	window := make([]byte, 1024)
	for i := range window {
		window[i] = byte(i)
	}

	h := rollsum.New()
	in := make([]byte, 0, h.Size())

	b.ResetTimer()
	h.Write(window)
	for i := 0; i < b.N; i++ {
		h.Roll(byte(1024 + i))
		h.Sum(in)
	}
}

func BenchmarkRolling128B(b *testing.B) {
	b.SetBytes(1024)
	window := make([]byte, 128)
	for i := range window {
		window[i] = byte(i)
	}

	h := rollsum.New()
	in := make([]byte, 0, h.Size())

	b.ResetTimer()
	h.Write(window)
	for i := 0; i < b.N; i++ {
		h.Roll(byte(128 + i))
		h.Sum(in)
	}
}