mirror of
https://github.com/golang/go.git
synced 2025-05-29 03:11:26 +00:00
hash/maphash: move purego-only helper functions to build tagged file
Hash.float64 and btoi helper functions are used only in the purego version. Move them to the build tagged file. Change-Id: I57f9a48966573ab0aee1de759eeddd2331967870 Reviewed-on: https://go-review.googlesource.com/c/go/+/675158 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
5e6a868b28
commit
d2db2372a2
@ -15,8 +15,6 @@ package maphash
|
|||||||
import (
|
import (
|
||||||
"hash"
|
"hash"
|
||||||
"internal/abi"
|
"internal/abi"
|
||||||
"internal/byteorder"
|
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Seed is a random value that selects the specific hash function
|
// A Seed is a random value that selects the specific hash function
|
||||||
@ -310,25 +308,3 @@ func WriteComparable[T comparable](h *Hash, x T) {
|
|||||||
}
|
}
|
||||||
writeComparable(h, x)
|
writeComparable(h, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hash) float64(f float64) {
|
|
||||||
if f == 0 {
|
|
||||||
h.WriteByte(0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var buf [8]byte
|
|
||||||
if f != f {
|
|
||||||
byteorder.LEPutUint64(buf[:], randUint64())
|
|
||||||
h.Write(buf[:])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
byteorder.LEPutUint64(buf[:], math.Float64bits(f))
|
|
||||||
h.Write(buf[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func btoi(b bool) byte {
|
|
||||||
if b {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"internal/byteorder"
|
"internal/byteorder"
|
||||||
|
"math"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
@ -175,3 +176,25 @@ func appendT(h *Hash, v reflect.Value) {
|
|||||||
}
|
}
|
||||||
panic(errors.New("maphash: hash of unhashable type " + v.Type().String()))
|
panic(errors.New("maphash: hash of unhashable type " + v.Type().String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Hash) float64(f float64) {
|
||||||
|
if f == 0 {
|
||||||
|
h.WriteByte(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var buf [8]byte
|
||||||
|
if f != f {
|
||||||
|
byteorder.LEPutUint64(buf[:], randUint64())
|
||||||
|
h.Write(buf[:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
byteorder.LEPutUint64(buf[:], math.Float64bits(f))
|
||||||
|
h.Write(buf[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func btoi(b bool) byte {
|
||||||
|
if b {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user