-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
hashing_hash.go
42 lines (32 loc) · 890 Bytes
/
hashing_hash.go
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
36
37
38
39
40
41
42
//go:build !no_hashing
// +build !no_hashing
package wildcarder
import (
"hash/maphash"
"github.com/d3mondev/resolvermt"
)
var hashSeed maphash.Seed = maphash.MakeSeed()
// QuestionHash is the type of the question stored in the cache.
type QuestionHash uint64
// AnswerHash is the type of an answer stored in the cache.
type AnswerHash struct {
Type resolvermt.RRtype
Hash uint64
}
// HashQuestion hashes a question and returns a QuestionHash.
func HashQuestion(question string) QuestionHash {
var hasher maphash.Hash
hasher.SetSeed(hashSeed)
hasher.WriteString(question)
return QuestionHash(hasher.Sum64())
}
// HashAnswer hashes a DNSAnswer and returns a AnswerHash.
func HashAnswer(answer DNSAnswer) AnswerHash {
var hasher maphash.Hash
hasher.SetSeed(hashSeed)
hasher.WriteString(answer.Answer)
return AnswerHash{
Type: answer.Type,
Hash: hasher.Sum64(),
}
}