File: fasthash32.go

package info (click to toggle)
golang-github-segmentio-fasthash 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 132 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package fasthash

import (
	"encoding/binary"
	"hash"
)

// HashString32 makes a hashing function from the hashing algorithm returned by f.
func HashString32(f func() hash.Hash32) func(string) uint32 {
	return func(s string) uint32 {
		h := f()
		h.Write([]byte(s))
		return h.Sum32()
	}
}

// HashBytes32 makes a hashing function from the hashing algorithm returned by f.
func HashBytes32(f func() hash.Hash32) func([]byte) uint32 {
	return func(s []byte) uint32 {
		h := f()
		h.Write(s)
		return h.Sum32()
	}
}

// HashUint32 makes a hashing function from the hashing algorithm return by f.
func HashUint32(f func() hash.Hash32) func(uint32) uint32 {
	return func(u uint32) uint32 {
		b := [4]byte{}
		binary.BigEndian.PutUint32(b[:], u)
		h := f()
		h.Write(b[:])
		return h.Sum32()
	}
}