forked from hexon/vectorcmp
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeswitch.go
141 lines (136 loc) · 4.37 KB
/
typeswitch.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
package vectorcmp
// VectorEquals compares each entry in rows to search and enables the corresponding bit in dst if equal.
// Prefer calling VectorEquals8/16/32/64 directly.
//
// clear(dst)
// for i, v := range rows {
// if search == v {
// dst[i/8] |= 1 << (i % 8)
// }
// }
func VectorEquals[T uint8 | uint16 | uint32 | uint64 | float32 | float64](dst []byte, search T, rows []T) {
switch rows := any(rows).(type) {
case []uint8:
VectorEquals8(dst, uint8(search), rows)
case []uint16:
VectorEquals16(dst, uint16(search), rows)
case []uint32:
VectorEquals32(dst, uint32(search), rows)
case []uint64:
VectorEquals64(dst, uint64(search), rows)
case []float32:
VectorEqualsFloat32(dst, float32(search), rows)
case []float64:
VectorEqualsFloat64(dst, float64(search), rows)
default:
panic("generic type not listed in type switch")
}
}
// VectorGreaterThan compares each entry in rows to search and enables the corresponding bit in dst if search > rows[i].
// Prefer calling VectorGreaterThan8/16/32/64 directly.
//
// clear(dst)
// for i, v := range rows {
// if search > v {
// dst[i/8] |= 1 << (i % 8)
// }
// }
func VectorGreaterThan[T uint8 | uint16 | uint32 | uint64 | float32 | float64](dst []byte, search T, rows []T) {
switch rows := any(rows).(type) {
case []uint8:
VectorGreaterThan8(dst, uint8(search), rows)
case []uint16:
VectorGreaterThan16(dst, uint16(search), rows)
case []uint32:
VectorGreaterThan32(dst, uint32(search), rows)
case []uint64:
VectorGreaterThan64(dst, uint64(search), rows)
case []float32:
VectorGreaterThanFloat32(dst, float32(search), rows)
case []float64:
VectorGreaterThanFloat64(dst, float64(search), rows)
default:
panic("generic type not listed in type switch")
}
}
// VectorLessThan compares each entry in rows to search and enables the corresponding bit in dst if search < rows[i].
// Prefer calling VectorLessThan8/16/32/64 directly.
//
// clear(dst)
// for i, v := range rows {
// if search < v {
// dst[i/8] |= 1 << (i % 8)
// }
// }
func VectorLessThan[T uint8 | uint16 | uint32 | uint64 | float32 | float64](dst []byte, search T, rows []T) {
switch rows := any(rows).(type) {
case []uint8:
VectorLessThan8(dst, uint8(search), rows)
case []uint16:
VectorLessThan16(dst, uint16(search), rows)
case []uint32:
VectorLessThan32(dst, uint32(search), rows)
case []uint64:
VectorLessThan64(dst, uint64(search), rows)
case []float32:
VectorLessThanFloat32(dst, float32(search), rows)
case []float64:
VectorLessThanFloat64(dst, float64(search), rows)
default:
panic("generic type not listed in type switch")
}
}
// VectorGreaterEquals compares each entry in rows to search and enables the corresponding bit in dst if search >= rows[i].
// Prefer calling VectorGreaterEquals8/16/32/64 directly.
//
// clear(dst)
// for i, v := range rows {
// if search >= v {
// dst[i/8] |= 1 << (i % 8)
// }
// }
func VectorGreaterEquals[T uint8 | uint16 | uint32 | uint64 | float32 | float64](dst []byte, search T, rows []T) {
switch rows := any(rows).(type) {
case []uint8:
VectorGreaterEquals8(dst, uint8(search), rows)
case []uint16:
VectorGreaterEquals16(dst, uint16(search), rows)
case []uint32:
VectorGreaterEquals32(dst, uint32(search), rows)
case []uint64:
VectorGreaterEquals64(dst, uint64(search), rows)
case []float32:
VectorGreaterEqualsFloat32(dst, float32(search), rows)
case []float64:
VectorGreaterEqualsFloat64(dst, float64(search), rows)
default:
panic("generic type not listed in type switch")
}
}
// VectorLesserEquals compares each entry in rows to search and enables the corresponding bit in dst if search <= rows[i].
// Prefer calling VectorLesserEquals8/16/32/64 directly.
//
// clear(dst)
// for i, v := range rows {
// if search <= v {
// dst[i/8] |= 1 << (i % 8)
// }
// }
func VectorLesserEquals[T uint8 | uint16 | uint32 | uint64 | float32 | float64](dst []byte, search T, rows []T) {
switch rows := any(rows).(type) {
case []uint8:
VectorLesserEquals8(dst, uint8(search), rows)
case []uint16:
VectorLesserEquals16(dst, uint16(search), rows)
case []uint32:
VectorLesserEquals32(dst, uint32(search), rows)
case []uint64:
VectorLesserEquals64(dst, uint64(search), rows)
case []float32:
VectorLesserEqualsFloat32(dst, float32(search), rows)
case []float64:
VectorLesserEqualsFloat64(dst, float64(search), rows)
default:
panic("generic type not listed in type switch")
}
}