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{ ...@@ -86,7 +86,6 @@ var pkgDeps = map[string][]string{
// L2 adds Unicode and strings processing. // L2 adds Unicode and strings processing.
"bufio": {"L0", "unicode/utf8", "bytes"}, "bufio": {"L0", "unicode/utf8", "bytes"},
"bytes": {"L0", "unicode", "unicode/utf8"}, "bytes": {"L0", "unicode", "unicode/utf8"},
"bytes/hash": {"L0"},
"path": {"L0", "unicode/utf8", "strings"}, "path": {"L0", "unicode/utf8", "strings"},
"strings": {"L0", "unicode", "unicode/utf8"}, "strings": {"L0", "unicode", "unicode/utf8"},
"unicode": {}, "unicode": {},
...@@ -95,7 +94,6 @@ var pkgDeps = map[string][]string{ ...@@ -95,7 +94,6 @@ var pkgDeps = map[string][]string{
"L1", "L1",
"bufio", "bufio",
"bytes", "bytes",
"bytes/hash",
"path", "path",
"strings", "strings",
"unicode", "unicode",
...@@ -116,6 +114,7 @@ var pkgDeps = map[string][]string{ ...@@ -116,6 +114,7 @@ var pkgDeps = map[string][]string{
"hash/crc32": {"L2", "hash"}, "hash/crc32": {"L2", "hash"},
"hash/crc64": {"L2", "hash"}, "hash/crc64": {"L2", "hash"},
"hash/fnv": {"L2", "hash"}, "hash/fnv": {"L2", "hash"},
"hash/maphash": {"L2", "hash"},
"image": {"L2", "image/color"}, // interfaces "image": {"L2", "image/color"}, // interfaces
"image/color": {"L2"}, // interfaces "image/color": {"L2"}, // interfaces
"image/color/palette": {"L2", "image/color"}, "image/color/palette": {"L2", "image/color"},
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 // hash functions are intended to be used to implement hash tables or
// other data structures that need to map arbitrary strings or byte // other data structures that need to map arbitrary strings or byte
// sequences to a uniform distribution of integers. The hash functions // sequences to a uniform distribution of integers. The hash functions
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// All bits of the Hash result are close to uniformly and // All bits of the Hash result are close to uniformly and
// independently distributed, so can be safely restricted to a range // independently distributed, so can be safely restricted to a range
// using bit masking, shifting, or modular arithmetic. // using bit masking, shifting, or modular arithmetic.
package hash package maphash
import ( import (
"unsafe" "unsafe"
...@@ -161,7 +161,7 @@ func rthash(b []byte, seed uint64) uint64 { ...@@ -161,7 +161,7 @@ func rthash(b []byte, seed uint64) uint64 {
//go:linkname runtime_memhash runtime.memhash //go:linkname runtime_memhash runtime.memhash
func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr 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. // the hash.Hash and hash.Hash64 interfaces.
func (h *Hash) Write(b []byte) (int, error) { func (h *Hash) Write(b []byte) (int, error) {
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package hash_test package maphash_test
import ( import (
"bytes/hash" "hash"
basehash "hash" "hash/maphash"
"testing" "testing"
) )
func TestUnseededHash(t *testing.T) { func TestUnseededHash(t *testing.T) {
m := map[uint64]struct{}{} m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
h := hash.New() h := maphash.New()
m[h.Hash()] = struct{}{} m[h.Hash()] = struct{}{}
} }
if len(m) < 900 { if len(m) < 900 {
...@@ -22,10 +22,10 @@ func TestUnseededHash(t *testing.T) { ...@@ -22,10 +22,10 @@ func TestUnseededHash(t *testing.T) {
} }
func TestSeededHash(t *testing.T) { func TestSeededHash(t *testing.T) {
s := hash.MakeSeed(1234) s := maphash.MakeSeed(1234)
m := map[uint64]struct{}{} m := map[uint64]struct{}{}
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
h := hash.New() h := maphash.New()
h.SetSeed(s) h.SetSeed(s)
m[h.Hash()] = struct{}{} m[h.Hash()] = struct{}{}
} }
...@@ -36,8 +36,8 @@ func TestSeededHash(t *testing.T) { ...@@ -36,8 +36,8 @@ func TestSeededHash(t *testing.T) {
func TestHashGrouping(t *testing.T) { func TestHashGrouping(t *testing.T) {
b := []byte("foo") b := []byte("foo")
h1 := hash.New() h1 := maphash.New()
h2 := hash.New() h2 := maphash.New()
h2.SetSeed(h1.Seed()) h2.SetSeed(h1.Seed())
h1.AddBytes(b) h1.AddBytes(b)
for _, x := range b { for _, x := range b {
...@@ -51,8 +51,8 @@ func TestHashGrouping(t *testing.T) { ...@@ -51,8 +51,8 @@ func TestHashGrouping(t *testing.T) {
func TestHashBytesVsString(t *testing.T) { func TestHashBytesVsString(t *testing.T) {
s := "foo" s := "foo"
b := []byte(s) b := []byte(s)
h1 := hash.New() h1 := maphash.New()
h2 := hash.New() h2 := maphash.New()
h2.SetSeed(h1.Seed()) h2.SetSeed(h1.Seed())
h1.AddString(s) h1.AddString(s)
h2.AddBytes(b) h2.AddBytes(b)
...@@ -66,7 +66,7 @@ func TestHashHighBytes(t *testing.T) { ...@@ -66,7 +66,7 @@ func TestHashHighBytes(t *testing.T) {
const N = 10 const N = 10
m := map[uint64]struct{}{} m := map[uint64]struct{}{}
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
h := hash.New() h := maphash.New()
h.AddString("foo") h.AddString("foo")
m[h.Hash()>>32] = struct{}{} m[h.Hash()>>32] = struct{}{}
} }
...@@ -76,5 +76,5 @@ func TestHashHighBytes(t *testing.T) { ...@@ -76,5 +76,5 @@ func TestHashHighBytes(t *testing.T) {
} }
// Make sure a Hash implements the hash.Hash and hash.Hash64 interfaces. // Make sure a Hash implements the hash.Hash and hash.Hash64 interfaces.
var _ basehash.Hash = &hash.Hash{} var _ hash.Hash = &maphash.Hash{}
var _ basehash.Hash64 = &hash.Hash{} var _ hash.Hash64 = &maphash.Hash{}
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package hash_test package maphash_test
import ( import (
"bytes/hash"
"fmt" "fmt"
"hash/maphash"
"math" "math"
"math/rand" "math/rand"
"runtime" "runtime"
...@@ -45,14 +45,14 @@ func TestSmhasherSanity(t *testing.T) { ...@@ -45,14 +45,14 @@ func TestSmhasherSanity(t *testing.T) {
} }
func bytesHash(b []byte, seed uint64) uint64 { func bytesHash(b []byte, seed uint64) uint64 {
h := hash.New() h := maphash.New()
h.SetSeed(hash.MakeSeed(seed)) h.SetSeed(maphash.MakeSeed(seed))
h.AddBytes(b) h.AddBytes(b)
return h.Hash() return h.Hash()
} }
func stringHash(s string, seed uint64) uint64 { func stringHash(s string, seed uint64) uint64 {
h := hash.New() h := maphash.New()
h.SetSeed(hash.MakeSeed(seed)) h.SetSeed(maphash.MakeSeed(seed))
h.AddString(s) h.AddString(s)
return h.Hash() 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