mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
runtime: add comments about the hash functions
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
//go:build runtime_memhash_leveldb
|
||||
// +build runtime_memhash_leveldb
|
||||
|
||||
// This is the hash function from Google's leveldb key-value storage system. It
|
||||
// processes 4 bytes at a time making it faster than the FNV hash for buffer
|
||||
// lengths > 16 bytes.
|
||||
|
||||
// https://github.com/google/leveldb
|
||||
// https://en.wikipedia.org/wiki/LevelDB
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
@@ -57,6 +64,8 @@ func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
|
||||
return h
|
||||
}
|
||||
|
||||
// hash64finalizer is a 64-bit integer mixing function from
|
||||
// https://web.archive.org/web/20120720045250/http://www.cris.com/~Ttwang/tech/inthash.htm
|
||||
func hash64finalizer(key uint64) uint64 {
|
||||
key = ^key + (key << 21) // key = (key << 21) - key - 1;
|
||||
key = key ^ (key >> 24)
|
||||
@@ -68,6 +77,9 @@ func hash64finalizer(key uint64) uint64 {
|
||||
return key
|
||||
}
|
||||
|
||||
// hash64 turns hash32 into a 64-bit hash, by use hash64finalizer to
|
||||
// mix the result of hash32 function combined with an xorshifted version of
|
||||
// the seed.
|
||||
func hash64(ptr unsafe.Pointer, n, seed uintptr) uint64 {
|
||||
h32 := hash32(ptr, n, seed)
|
||||
return hash64finalizer((uint64(h32^xorshift32(uint32(seed))) << 32) | uint64(h32))
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
//go:build runtime_memhash_tsip
|
||||
// +build runtime_memhash_tsip
|
||||
|
||||
// This is the tsip hash developed by Damian Gryski, based on ideas from SipHash.
|
||||
// It is slower than leveldb's hash, but should be "stronger".
|
||||
|
||||
// https://en.wikipedia.org/wiki/SipHash
|
||||
// https://github.com/veorq/SipHash
|
||||
// https://github.com/dgryski/tsip
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
@@ -26,8 +33,6 @@ func ptrToSlice(ptr unsafe.Pointer, n uintptr) []byte {
|
||||
return p
|
||||
}
|
||||
|
||||
// tsip hash -- github.com/dgryski/tsip
|
||||
|
||||
type sip struct {
|
||||
v0, v1 uint64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user