Commit 35cfe059 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

hash/maphash: move bytes/hash to hash/maphash

Fixes #34778

Change-Id: If8225a7c41cb2af3f67157fb9670eef86272e85e
Reviewed-on: https://go-review.googlesource.com/c/go/+/204997
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent dc0c23ec
......@@ -86,7 +86,6 @@ var pkgDeps = map[string][]string{
// L2 adds Unicode and strings processing.
"bufio": {"L0", "unicode/utf8", "bytes"},
"bytes": {"L0", "unicode", "unicode/utf8"},
"bytes/hash": {"L0"},
"path": {"L0", "unicode/utf8", "strings"},
"strings": {"L0", "unicode", "unicode/utf8"},
"unicode": {},
......@@ -95,7 +94,6 @@ var pkgDeps = map[string][]string{
"L1",
"bufio",
"bytes",
"bytes/hash",
"path",
"strings",
"unicode",
......@@ -116,6 +114,7 @@ var pkgDeps = map[string][]string{
"hash/crc32": {"L2", "hash"},
"hash/crc64": {"L2", "hash"},
"hash/fnv": {"L2", "hash"},
"hash/maphash": {"L2", "hash"},
"image": {"L2", "image/color"}, // interfaces
"image/color": {"L2"}, // interfaces
"image/color/palette": {"L2", "image/color"},
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package bytes/hash provides hash functions on byte sequences. These
// Package hash/maphash provides hash functions on byte sequences. These
// hash functions are intended to be used to implement hash tables or
// other data structures that need to map arbitrary strings or byte
// sequences to a uniform distribution of integers. The hash functions
......@@ -29,7 +29,7 @@
// All bits of the Hash result are close to uniformly and
// independently distributed, so can be safely restricted to a range
// using bit masking, shifting, or modular arithmetic.
package hash
package maphash
import (
"unsafe"
......@@ -161,7 +161,7 @@ func rthash(b []byte, seed uint64) uint64 {
//go:linkname runtime_memhash runtime.memhash
func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr
// Wrapper functions so that a bytes/hash.Hash implements
// Wrapper functions so that a hash/maphash.Hash implements
// the hash.Hash and hash.Hash64 interfaces.
func (h *Hash) Write(b []byte) (int, error) {
......
......@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hash_test
package maphash_test
import (
"bytes/hash"
basehash "hash"
"hash"
"hash/maphash"
"testing"
)
func TestUnseededHash(t *testing.T) {
m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ {
h := hash.New()
h := maphash.New()
m[h.Hash()] = struct{}{}
}
if len(m) < 900 {
......@@ -22,10 +22,10 @@ func TestUnseededHash(t *testing.T) {
}
func TestSeededHash(t *testing.T) {
s := hash.MakeSeed(1234)
s := maphash.MakeSeed(1234)
m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ {
h := hash.New()
h := maphash.New()
h.SetSeed(s)
m[h.Hash()] = struct{}{}
}
......@@ -36,8 +36,8 @@ func TestSeededHash(t *testing.T) {
func TestHashGrouping(t *testing.T) {
b := []byte("foo")
h1 := hash.New()
h2 := hash.New()
h1 := maphash.New()
h2 := maphash.New()
h2.SetSeed(h1.Seed())
h1.AddBytes(b)
for _, x := range b {
......@@ -51,8 +51,8 @@ func TestHashGrouping(t *testing.T) {
func TestHashBytesVsString(t *testing.T) {
s := "foo"
b := []byte(s)
h1 := hash.New()
h2 := hash.New()
h1 := maphash.New()
h2 := maphash.New()
h2.SetSeed(h1.Seed())
h1.AddString(s)
h2.AddBytes(b)
......@@ -66,7 +66,7 @@ func TestHashHighBytes(t *testing.T) {
const N = 10
m := map[uint64]struct{}{}
for i := 0; i < N; i++ {
h := hash.New()
h := maphash.New()
h.AddString("foo")
m[h.Hash()>>32] = struct{}{}
}
......@@ -76,5 +76,5 @@ func TestHashHighBytes(t *testing.T) {
}
// Make sure a Hash implements the hash.Hash and hash.Hash64 interfaces.
var _ basehash.Hash = &hash.Hash{}
var _ basehash.Hash64 = &hash.Hash{}
var _ hash.Hash = &maphash.Hash{}
var _ hash.Hash64 = &maphash.Hash{}
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hash_test
package maphash_test
import (
"bytes/hash"
"fmt"
"hash/maphash"
"math"
"math/rand"
"runtime"
......@@ -45,14 +45,14 @@ func TestSmhasherSanity(t *testing.T) {
}
func bytesHash(b []byte, seed uint64) uint64 {
h := hash.New()
h.SetSeed(hash.MakeSeed(seed))
h := maphash.New()
h.SetSeed(maphash.MakeSeed(seed))
h.AddBytes(b)
return h.Hash()
}
func stringHash(s string, seed uint64) uint64 {
h := hash.New()
h.SetSeed(hash.MakeSeed(seed))
h := maphash.New()
h.SetSeed(maphash.MakeSeed(seed))
h.AddString(s)
return h.Hash()
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment