Skip to content

Commit

Permalink
hash: add available godoc link
Browse files Browse the repository at this point in the history
Change-Id: Ieb43f28400e9ded3dc7e57f27f6d7514b14cc66d
Reviewed-on: https://go-review.googlesource.com/c/go/+/535083
Run-TryBot: shuang cui <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
cuishuang authored and gopherbot committed Oct 13, 2023
1 parent ba5ebc0 commit 0700bcf
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/hash/adler32/adler32.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (d *digest) Reset() { *d = 1 }

// New returns a new hash.Hash32 computing the Adler-32 checksum. Its
// Sum method will lay the value out in big-endian byte order. The
// returned Hash32 also implements encoding.BinaryMarshaler and
// encoding.BinaryUnmarshaler to marshal and unmarshal the internal
// returned Hash32 also implements [encoding.BinaryMarshaler] and
// [encoding.BinaryUnmarshaler] to marshal and unmarshal the internal
// state of the hash.
func New() hash.Hash32 {
d := new(digest)
Expand Down
22 changes: 11 additions & 11 deletions src/hash/crc32/crc32.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func castagnoliInit() {
haveCastagnoli.Store(true)
}

// IEEETable is the table for the IEEE polynomial.
// IEEETable is the table for the [IEEE] polynomial.
var IEEETable = simpleMakeTable(IEEE)

// ieeeTable8 is the slicing8Table for IEEE
Expand All @@ -118,8 +118,8 @@ func ieeeInit() {
}
}

// MakeTable returns a Table constructed from the specified polynomial.
// The contents of this Table must not be modified.
// MakeTable returns a [Table] constructed from the specified polynomial.
// The contents of this [Table] must not be modified.
func MakeTable(poly uint32) *Table {
switch poly {
case IEEE:
Expand All @@ -139,10 +139,10 @@ type digest struct {
tab *Table
}

// New creates a new hash.Hash32 computing the CRC-32 checksum using the
// polynomial represented by the Table. Its Sum method will lay the
// New creates a new [hash.Hash32] computing the CRC-32 checksum using the
// polynomial represented by the [Table]. Its Sum method will lay the
// value out in big-endian byte order. The returned Hash32 also
// implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
// implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to
// marshal and unmarshal the internal state of the hash.
func New(tab *Table) hash.Hash32 {
if tab == IEEETable {
Expand All @@ -151,10 +151,10 @@ func New(tab *Table) hash.Hash32 {
return &digest{0, tab}
}

// NewIEEE creates a new hash.Hash32 computing the CRC-32 checksum using
// the IEEE polynomial. Its Sum method will lay the value out in
// NewIEEE creates a new [hash.Hash32] computing the CRC-32 checksum using
// the [IEEE] polynomial. Its Sum method will lay the value out in
// big-endian byte order. The returned Hash32 also implements
// encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to marshal
// [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to marshal
// and unmarshal the internal state of the hash.
func NewIEEE() hash.Hash32 { return New(IEEETable) }

Expand Down Expand Up @@ -242,11 +242,11 @@ func (d *digest) Sum(in []byte) []byte {
}

// Checksum returns the CRC-32 checksum of data
// using the polynomial represented by the Table.
// using the polynomial represented by the [Table].
func Checksum(data []byte, tab *Table) uint32 { return Update(0, tab, data) }

// ChecksumIEEE returns the CRC-32 checksum of data
// using the IEEE polynomial.
// using the [IEEE] polynomial.
func ChecksumIEEE(data []byte) uint32 {
ieeeOnce.Do(ieeeInit)
return updateIEEE(0, data)
Expand Down
10 changes: 5 additions & 5 deletions src/hash/crc64/crc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func buildSlicing8Tables() {
slicing8TableECMA = makeSlicingBy8Table(makeTable(ECMA))
}

// MakeTable returns a Table constructed from the specified polynomial.
// The contents of this Table must not be modified.
// MakeTable returns a [Table] constructed from the specified polynomial.
// The contents of this [Table] must not be modified.
func MakeTable(poly uint64) *Table {
buildSlicing8TablesOnce()
switch poly {
Expand Down Expand Up @@ -93,9 +93,9 @@ type digest struct {
}

// New creates a new hash.Hash64 computing the CRC-64 checksum using the
// polynomial represented by the Table. Its Sum method will lay the
// polynomial represented by the [Table]. Its Sum method will lay the
// value out in big-endian byte order. The returned Hash64 also
// implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
// implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to
// marshal and unmarshal the internal state of the hash.
func New(tab *Table) hash.Hash64 { return &digest{0, tab} }

Expand Down Expand Up @@ -210,7 +210,7 @@ func (d *digest) Sum(in []byte) []byte {
}

// Checksum returns the CRC-64 checksum of data
// using the polynomial represented by the Table.
// using the polynomial represented by the [Table].
func Checksum(data []byte, tab *Table) uint64 { return update(0, tab, data) }

// tableSum returns the ISO checksum of table t.
Expand Down
12 changes: 6 additions & 6 deletions src/hash/fnv/fnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,35 @@ const (
prime128Shift = 24
)

// New32 returns a new 32-bit FNV-1 hash.Hash.
// New32 returns a new 32-bit FNV-1 [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New32() hash.Hash32 {
var s sum32 = offset32
return &s
}

// New32a returns a new 32-bit FNV-1a hash.Hash.
// New32a returns a new 32-bit FNV-1a [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New32a() hash.Hash32 {
var s sum32a = offset32
return &s
}

// New64 returns a new 64-bit FNV-1 hash.Hash.
// New64 returns a new 64-bit FNV-1 [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New64() hash.Hash64 {
var s sum64 = offset64
return &s
}

// New64a returns a new 64-bit FNV-1a hash.Hash.
// New64a returns a new 64-bit FNV-1a [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New64a() hash.Hash64 {
var s sum64a = offset64
return &s
}

// New128 returns a new 128-bit FNV-1 hash.Hash.
// New128 returns a new 128-bit FNV-1 [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New128() hash.Hash {
var s sum128
Expand All @@ -75,7 +75,7 @@ func New128() hash.Hash {
return &s
}

// New128a returns a new 128-bit FNV-1a hash.Hash.
// New128a returns a new 128-bit FNV-1a [hash.Hash].
// Its Sum method will lay the value out in big-endian byte order.
func New128a() hash.Hash {
var s sum128a
Expand Down
6 changes: 3 additions & 3 deletions src/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import "io"

// Hash is the common interface implemented by all hash functions.
//
// Hash implementations in the standard library (e.g. hash/crc32 and
// crypto/sha256) implement the encoding.BinaryMarshaler and
// encoding.BinaryUnmarshaler interfaces. Marshaling a hash implementation
// Hash implementations in the standard library (e.g. [hash/crc32] and
// [crypto/sha256]) implement the [encoding.BinaryMarshaler] and
// [encoding.BinaryUnmarshaler] interfaces. Marshaling a hash implementation
// allows its internal state to be saved and used for additional processing
// later, without having to re-write the data previously written to the hash.
// The hash state may contain portions of the input in its original form,
Expand Down
28 changes: 14 additions & 14 deletions src/hash/maphash/maphash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
// 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 on unsigned 64-bit integers.
// Each different instance of a hash table or data structure should use its own Seed.
// Each different instance of a hash table or data structure should use its own [Seed].
//
// The hash functions are not cryptographically secure.
// (See crypto/sha256 and crypto/sha512 for cryptographic use.)
package maphash

// A Seed is a random value that selects the specific hash function
// computed by a Hash. If two Hashes use the same Seeds, they
// computed by a [Hash]. If two Hashes use the same Seeds, they
// will compute the same hash values for any given input.
// If two Hashes use different Seeds, they are very likely to compute
// distinct hash values for any given input.
//
// A Seed must be initialized by calling MakeSeed.
// The zero seed is uninitialized and not valid for use with Hash's SetSeed method.
// A Seed must be initialized by calling [MakeSeed].
// The zero seed is uninitialized and not valid for use with [Hash]'s SetSeed method.
//
// Each Seed value is local to a single process and cannot be serialized
// or otherwise recreated in a different process.
Expand Down Expand Up @@ -122,7 +122,7 @@ func (h *Hash) initSeed() {
}

// WriteByte adds b to the sequence of bytes hashed by h.
// It never fails; the error result is for implementing io.ByteWriter.
// It never fails; the error result is for implementing [io.ByteWriter].
func (h *Hash) WriteByte(b byte) error {
if h.n == len(h.buf) {
h.flush()
Expand All @@ -133,7 +133,7 @@ func (h *Hash) WriteByte(b byte) error {
}

// Write adds b to the sequence of bytes hashed by h.
// It always writes all of b and never fails; the count and error result are for implementing io.Writer.
// It always writes all of b and never fails; the count and error result are for implementing [io.Writer].
func (h *Hash) Write(b []byte) (int, error) {
size := len(b)
// Deal with bytes left over in h.buf.
Expand Down Expand Up @@ -165,7 +165,7 @@ func (h *Hash) Write(b []byte) (int, error) {
}

// WriteString adds the bytes of s to the sequence of bytes hashed by h.
// It always writes all of s and never fails; the count and error result are for implementing io.StringWriter.
// It always writes all of s and never fails; the count and error result are for implementing [io.StringWriter].
func (h *Hash) WriteString(s string) (int, error) {
// WriteString mirrors Write. See Write for comments.
size := len(s)
Expand Down Expand Up @@ -196,10 +196,10 @@ func (h *Hash) Seed() Seed {
return h.seed
}

// SetSeed sets h to use seed, which must have been returned by MakeSeed
// or by another Hash's Seed method.
// Two Hash objects with the same seed behave identically.
// Two Hash objects with different seeds will very likely behave differently.
// SetSeed sets h to use seed, which must have been returned by [MakeSeed]
// or by another [Hash.Seed] method.
// Two [Hash] objects with the same seed behave identically.
// Two [Hash] objects with different seeds will very likely behave differently.
// Any bytes added to h before this call will be discarded.
func (h *Hash) SetSeed(seed Seed) {
if seed.s == 0 {
Expand Down Expand Up @@ -230,7 +230,7 @@ func (h *Hash) flush() {

// Sum64 returns h's current 64-bit value, which depends on
// h's seed and the sequence of bytes added to h since the
// last call to Reset or SetSeed.
// last call to [Hash.Reset] or [Hash.SetSeed].
//
// All bits of the Sum64 result are close to uniformly and
// independently distributed, so it can be safely reduced
Expand All @@ -255,8 +255,8 @@ func MakeSeed() Seed {
}

// Sum appends the hash's current 64-bit value to b.
// It exists for implementing hash.Hash.
// For direct calls, it is more efficient to use Sum64.
// It exists for implementing [hash.Hash].
// For direct calls, it is more efficient to use [Hash.Sum64].
func (h *Hash) Sum(b []byte) []byte {
x := h.Sum64()
return append(b,
Expand Down

0 comments on commit 0700bcf

Please sign in to comment.