-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhash.go
48 lines (44 loc) · 784 Bytes
/
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
43
44
45
46
47
48
package wizard
import (
"fmt"
"hash/crc64"
"io"
)
var hashTable = crc64.MakeTable(crc64.ISO)
// getInt64 returns int64 value
func getInt64(v interface{}) int64 {
switch t := v.(type) {
case int64:
return t
case int:
return int64(t)
case int8:
return int64(t)
case int16:
return int64(t)
case int32:
return int64(t)
case uint:
return int64(t)
case uint8:
return int64(t)
case uint16:
return int64(t)
case uint32:
return int64(t)
case uint64:
return int64(t)
case float32:
return int64(t)
case float64:
return int64(t)
}
return hashToInt64(v)
}
// hashToInt64 converts any value to int64 using crc64
func hashToInt64(v interface{}) int64 {
str := fmt.Sprint(v)
h := crc64.New(hashTable)
io.WriteString(h, str)
return int64(h.Sum64())
}