-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.go
More file actions
62 lines (48 loc) · 889 Bytes
/
server.go
File metadata and controls
62 lines (48 loc) · 889 Bytes
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
55
56
57
58
59
60
61
62
package main
import (
"unsafe"
)
var dbDictType = dictType{
hashFunction: dictSdsHash,
keyDup: nil,
valDup: nil,
keyCompare: dictCompare,
keyDestructor: nil,
valDestructor: nil,
}
func dictSdsHash(key string) int {
return dictGenHashFunction(key, len(key))
}
func dictGenHashFunction(key string, kLen int) int {
var seed int = dict_hash_function_seed
var m int = 0x5bd1e995
var r int = 24
var h int = seed ^ kLen
runes := []rune(key)
pos := 0
for kLen >= 4 {
k := *(*int)(unsafe.Pointer(&runes[pos]))
k *= m
k ^= k >> r
k *= m
h ^= k
pos += 4
kLen -= 4
}
switch kLen {
case 3:
h ^= int(runes[2]) << 16
case 2:
h ^= int(runes[1]) << 8
case 1:
h ^= int(runes[0])
h *= m
}
h ^= h >> 13
h *= m
h ^= h >> 15
return h
}
func dictCompare(privdata *interface{}, key1 string, key2 string) bool {
return key1 == key2
}