Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathhash.go
More file actions
Latest commit
54 lines (50 loc) · 1.17 KB
/
Copy pathhash.go
File metadata and controls
54 lines (50 loc) · 1.17 KB
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
49
50
51
52
53
54
package devstatscode
import (
"fmt"
"hash/fnv"
"strconv"
)
// HashStrings - returns unique Hash for strings array
// This value is supposed to be used as ID (negative) to mark it was artificially generated
funcHashStrings(strs []string) int {
h:=fnv.New64a()
s:=""
for_, str:=rangestrs {
s+=str
}
_, _=h.Write([]byte(s))
res:=int(h.Sum64())
ifres>0 {
res*=-1
}
ifres==-0x8000000000000000 {
returnHashStrings(append(strs, "a"))
}
returnres
}
// HashObject takes map[string]interface{} and keys from []string and returns hash string
// from given keys from map
funcHashObject(ivmap[string]interface{}, keys []string) string {
h:=fnv.New64a()
s:=""
for_, key:=rangekeys {
v, ok:=iv[key]
if!ok {
Fatalf("HashObject: %+v missing %s key", iv, key)
}
s+=fmt.Sprintf("%v", v)
}
_, _=h.Write([]byte(s))
returnstrconv.FormatUint(h.Sum64(), 36)
}
// HashArray takes []interface{} and returns hash string
// from given keys from map
funcHashArray(ia []interface{}) string {
h:=fnv.New64a()
s:=""
for_, iv:=rangeia {
s+=fmt.Sprintf("%v", iv)
}
_, _=h.Write([]byte(s))
returnstrconv.FormatUint(h.Sum64(), 36)
}