-
Notifications
You must be signed in to change notification settings - Fork 0
/
series_helpers.go
153 lines (136 loc) · 3.06 KB
/
series_helpers.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
package gandalff
// This function merges two null masks into one.
// Any of the two masks can be empty.
func __mergeNullMasks(s1Len int, s1Nullable bool, s1Mask []uint8, s2Len int, s2Nullable bool, s2Mask []uint8) (bool, []uint8) {
dataLen := s1Len + s2Len
if s1Nullable {
if dataLen > len(s1Mask)<<3 {
s1Mask = append(s1Mask, make([]uint8, (dataLen>>3)-len(s1Mask)+1)...)
}
if s2Nullable {
sIdx := s1Len
oIdx := 0
for _, v := range s2Mask {
for j := 0; j < 8; j++ {
if v&(1<<uint(j)) != 0 {
s1Mask[sIdx>>3] |= 1 << uint(sIdx%8)
}
sIdx++
oIdx++
}
}
return true, s1Mask
} else {
return true, s1Mask
}
} else {
if s2Nullable {
s1Mask = make([]uint8, (dataLen>>3)+1)
sIdx := s1Len
oIdx := 0
for _, v := range s2Mask {
for j := 0; j < 8; j++ {
if v&(1<<uint(j)) != 0 {
s1Mask[sIdx>>3] |= 1 << uint(sIdx%8)
}
sIdx++
oIdx++
}
}
return true, s1Mask
} else {
return false, make([]uint8, 0)
}
}
}
func __binVecInit(size int, flag bool) []uint8 {
vec := make([]uint8, (size+7)>>3)
if flag {
for i := range vec {
vec[i] = 0xFF
}
if size%8 != 0 {
vec[len(vec)-1] >>= uint(8 - (size % 8))
}
}
return vec
}
func __binVecFromBools(v []bool) []uint8 {
binVec := make([]uint8, (len(v)+7)>>3)
for i := 0; i < len(v); i++ {
if v[i] {
binVec[i>>3] |= 1 << uint(i%8)
}
}
return binVec
}
func __binVecSet(v []uint8, i int, flag bool) {
if flag {
v[i>>3] |= 1 << uint(i%8)
} else {
v[i>>3] &= ^(1 << uint(i%8))
}
}
func __binVecResize(v []uint8, size int) []uint8 {
if size <= len(v)<<3 {
return v
}
v2 := make([]uint8, (size+7)>>3)
copy(v2, v)
return v2
}
func __binVecFilterByIndices(srcVec []uint8, indices []int) []uint8 {
dstVec := make([]uint8, (len(indices)+7)>>3)
for dstIdx, srcIdx := range indices {
if srcIdx%8 > dstIdx%8 {
dstVec[dstIdx>>3] |= ((srcVec[srcIdx>>3] & (1 << uint(srcIdx%8))) >> uint(srcIdx%8-dstIdx%8))
} else {
dstVec[dstIdx>>3] |= ((srcVec[srcIdx>>3] & (1 << uint(srcIdx%8))) << uint(dstIdx%8-srcIdx%8))
}
}
return dstVec
}
func __binVecCount(v []uint8) int {
count := 0
for _, x := range v {
for x != 0 {
count += int(x & 1)
x >>= 1
}
}
return count
}
// This function computes the bitwise OR of two binary vectors.
// The result is stored in the third argument.
func __binVecOrSS(a, b, res []uint8) {
res[0] = a[0] | b[0]
}
// This function computes the bitwise OR of a binary vectors.
// The result is stored in the second argument.
func __binVecOrSV(a, b, res []uint8) {
if a[0] == 0 {
copy(res, b)
} else {
for i := range res {
res[i] = 0xFF
}
}
}
// This function computes the bitwise OR of a binary vectors.
// The result is stored in the second argument.
func __binVecOrVS(a, b, res []uint8) {
if b[0] == 0 {
copy(res, a)
} else {
for i := range res {
res[i] = 0xFF
}
}
}
// This function computes the bitwise OR of two binary vectors.
// The result is stored in the third argument.
func __binVecOrVV(a, b, res []uint8) {
for i := range res {
res[i] = a[i] | b[i]
}
}