forked from zyedidia/generic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
165 lines (145 loc) · 2.79 KB
/
types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package generic
import "github.com/segmentio/fasthash/fnv1a"
type Uint8 uint8
type Uint16 uint16
type Uint32 uint32
type Uint64 uint64
type Uint uint
type Int8 int8
type Int16 int16
type Int32 int32
type Int64 int64
type Int int
type Float32 float32
type Float64 float64
type Bool bool
type String string
type ByteSlice []byte
func (u Uint8) Less(other Uint8) bool {
return u < other
}
func (u Uint8) Equals(other Uint8) bool {
return u == other
}
func (u Uint8) Hash() uint64 {
return hash(uint64(u))
}
func (u Uint16) Less(other Uint16) bool {
return u < other
}
func (u Uint16) Equals(other Uint16) bool {
return u == other
}
func (u Uint16) Hash() uint64 {
return hash(uint64(u))
}
func (u Uint32) Less(other Uint32) bool {
return u < other
}
func (u Uint32) Equals(other Uint32) bool {
return u == other
}
func (u Uint32) Hash() uint64 {
return hash(uint64(u))
}
func (u Uint64) Less(other Uint64) bool {
return u < other
}
func (u Uint64) Equals(other Uint64) bool {
return u == other
}
func (u Uint64) Hash() uint64 {
return hash(uint64(u))
}
func (u Uint) Less(other Uint) bool {
return u < other
}
func (u Uint) Equals(other Uint) bool {
return u == other
}
func (u Uint) Hash() uint64 {
return hash(uint64(u))
}
func (i Int8) Less(other Int8) bool {
return i < other
}
func (i Int8) Equals(other Int8) bool {
return i == other
}
func (i Int8) Hash() uint64 {
return hash(uint64(i))
}
func (i Int16) Less(other Int16) bool {
return i < other
}
func (i Int16) Equals(other Int16) bool {
return i == other
}
func (i Int16) Hash() uint64 {
return hash(uint64(i))
}
func (i Int32) Less(other Int32) bool {
return i < other
}
func (i Int32) Equals(other Int32) bool {
return i == other
}
func (i Int32) Hash() uint64 {
return hash(uint64(i))
}
func (i Int64) Less(other Int64) bool {
return i < other
}
func (i Int64) Equals(other Int64) bool {
return i == other
}
func (i Int64) Hash() uint64 {
return hash(uint64(i))
}
func (i Int) Less(other Int) bool {
return i < other
}
func (i Int) Equals(other Int) bool {
return i == other
}
func (i Int) Hash() uint64 {
return hash(uint64(i))
}
func (b Bool) Equals(other Bool) bool {
return b == other
}
func (b Bool) Hash() uint64 {
if b {
return 1
}
return 0
}
func (s String) Less(other String) bool {
return s < other
}
func (s String) Equals(other String) bool {
return s == other
}
func (s String) Hash() uint64 {
return fnv1a.HashString64(string(s))
}
func (b ByteSlice) Equals(other ByteSlice) bool {
// TODO: update when stdlib slices package is available
for i := range b {
if b[i] != other[i] {
return false
}
}
return true
}
func (b ByteSlice) Hash() uint64 {
return fnv1a.HashBytes64([]byte(b))
}
func hash(u uint64) uint64 {
u ^= u >> 33
u *= 0xff51afd7ed558ccd
u ^= u >> 33
u *= 0xc4ceb9fe1a85ec53
u ^= u >> 33
return u
}