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
...@@ -84,18 +84,16 @@ var pkgDeps = map[string][]string{ ...@@ -84,18 +84,16 @@ 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": {},
"L2": { "L2": {
"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"},
...@@ -244,51 +243,51 @@ var pkgDeps = map[string][]string{ ...@@ -244,51 +243,51 @@ var pkgDeps = map[string][]string{
"go/types": {"L4", "GOPARSER", "container/heap", "go/constant"}, "go/types": {"L4", "GOPARSER", "container/heap", "go/constant"},
// One of a kind. // One of a kind.
"archive/tar": {"L4", "OS", "syscall", "os/user"}, "archive/tar": {"L4", "OS", "syscall", "os/user"},
"archive/zip": {"L4", "OS", "compress/flate"}, "archive/zip": {"L4", "OS", "compress/flate"},
"container/heap": {"sort"}, "container/heap": {"sort"},
"compress/bzip2": {"L4"}, "compress/bzip2": {"L4"},
"compress/flate": {"L4"}, "compress/flate": {"L4"},
"compress/gzip": {"L4", "compress/flate"}, "compress/gzip": {"L4", "compress/flate"},
"compress/lzw": {"L4"}, "compress/lzw": {"L4"},
"compress/zlib": {"L4", "compress/flate"}, "compress/zlib": {"L4", "compress/flate"},
"context": {"errors", "internal/reflectlite", "sync", "sync/atomic", "time"}, "context": {"errors", "internal/reflectlite", "sync", "sync/atomic", "time"},
"database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"}, "database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"},
"database/sql/driver": {"L4", "context", "time", "database/sql/internal"}, "database/sql/driver": {"L4", "context", "time", "database/sql/internal"},
"debug/dwarf": {"L4"}, "debug/dwarf": {"L4"},
"debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"}, "debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/gosym": {"L4"}, "debug/gosym": {"L4"},
"debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"}, "debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"}, "debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"},
"debug/plan9obj": {"L4", "OS"}, "debug/plan9obj": {"L4", "OS"},
"encoding": {"L4"}, "encoding": {"L4"},
"encoding/ascii85": {"L4"}, "encoding/ascii85": {"L4"},
"encoding/asn1": {"L4", "math/big"}, "encoding/asn1": {"L4", "math/big"},
"encoding/csv": {"L4"}, "encoding/csv": {"L4"},
"encoding/gob": {"L4", "OS", "encoding"}, "encoding/gob": {"L4", "OS", "encoding"},
"encoding/hex": {"L4"}, "encoding/hex": {"L4"},
"encoding/json": {"L4", "encoding"}, "encoding/json": {"L4", "encoding"},
"encoding/pem": {"L4"}, "encoding/pem": {"L4"},
"encoding/xml": {"L4", "encoding"}, "encoding/xml": {"L4", "encoding"},
"flag": {"L4", "OS"}, "flag": {"L4", "OS"},
"go/build": {"L4", "OS", "GOPARSER", "internal/goroot", "internal/goversion"}, "go/build": {"L4", "OS", "GOPARSER", "internal/goroot", "internal/goversion"},
"html": {"L4"}, "html": {"L4"},
"image/draw": {"L4", "image/internal/imageutil"}, "image/draw": {"L4", "image/internal/imageutil"},
"image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"}, "image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"},
"image/internal/imageutil": {"L4"}, "image/internal/imageutil": {"L4"},
"image/jpeg": {"L4", "image/internal/imageutil"}, "image/jpeg": {"L4", "image/internal/imageutil"},
"image/png": {"L4", "compress/zlib"}, "image/png": {"L4", "compress/zlib"},
"index/suffixarray": {"L4", "regexp"}, "index/suffixarray": {"L4", "regexp"},
"internal/goroot": {"L4", "OS"}, "internal/goroot": {"L4", "OS"},
"internal/singleflight": {"sync"}, "internal/singleflight": {"sync"},
"internal/trace": {"L4", "OS", "container/heap"}, "internal/trace": {"L4", "OS", "container/heap"},
"internal/xcoff": {"L4", "OS", "debug/dwarf"}, "internal/xcoff": {"L4", "OS", "debug/dwarf"},
"math/big": {"L4"}, "math/big": {"L4"},
"mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"}, "mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"},
"mime/quotedprintable": {"L4"}, "mime/quotedprintable": {"L4"},
"net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"}, "net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"},
"net/url": {"L4"}, "net/url": {"L4"},
"plugin": {"L0", "OS", "CGO"}, "plugin": {"L0", "OS", "CGO"},
"runtime/pprof/internal/profile": {"L4", "OS", "compress/gzip", "regexp"}, "runtime/pprof/internal/profile": {"L4", "OS", "compress/gzip", "regexp"},
"testing/internal/testdeps": {"L4", "internal/testlog", "runtime/pprof", "regexp"}, "testing/internal/testdeps": {"L4", "internal/testlog", "runtime/pprof", "regexp"},
"text/scanner": {"L4", "OS"}, "text/scanner": {"L4", "OS"},
......
...@@ -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