-
Notifications
You must be signed in to change notification settings - Fork 1
/
select_test.go
148 lines (141 loc) · 4.32 KB
/
select_test.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
package ef
import "testing"
func TestSelect64(t *testing.T) {
for i, tc := range []struct {
x uint
ranks []uint
want []int
}{
{
0xFFFFFFFFFFFFFFFF,
[]uint{
0, 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,
},
[]int{
0, 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,
},
},
{
0x8888888888888888,
[]uint{0, 1, 2, 15},
[]int{3, 7, 11, 63},
},
{
0b_1000_0101_0110_0101_0001_0000_0010_1001,
[]uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
[]int{0, 3, 5, 12, 16, 18, 21, 22, 24, 26, 31},
},
{
0b_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010,
[]uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
[]int{1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61},
},
} {
for j, r := range tc.ranks {
got := select64(tc.x, r)
if got != tc.want[j] {
t.Errorf("tc: %d, select(%b, %d) = got: %d != want: %d\n", i, tc.x, r, got, tc.want[j])
}
}
}
}
func TestSelect1(t *testing.T) {
for i, tc := range []struct {
b uint
ranks []int
want []int
}{
{
0xFFFFFFFFFFFFFFFF,
[]int{
0, 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,
},
[]int{
0, 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,
},
},
{
0x8888888888888888,
[]int{0, 1, 2, 15},
[]int{3, 7, 11, 63},
},
{
0b_1000_0101_0110_0101_0001_0000_0010_1001,
[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
[]int{0, 3, 5, 12, 16, 18, 21, 22, 24, 26, 31},
},
{
0b_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010,
[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
[]int{1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61},
},
} {
d := Dict{b: []uint{tc.b}}
for j, r := range tc.ranks {
got := d.select1(r)
if got != tc.want[j] {
t.Errorf("tc: %d, select(%b, %d) = got: %d != want: %d\n", i, tc.b, r, got, tc.want[j])
}
}
}
}
func TestSelect0(t *testing.T) {
for i, tc := range []struct {
b uint
ranks []int
want []int
}{
{
0x0000000000000000,
[]int{
0, 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,
},
[]int{
0, 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,
},
},
{
0x7777777777777777,
[]int{0, 1, 2, 15},
[]int{3, 7, 11, 63},
},
{
0b_1000_0101_0110_0101_0001_0000_0010_1001,
[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
[]int{1, 2, 4, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 19, 20, 23, 25, 27, 28, 29, 30},
},
// { // TODO
// 0b_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010_0100_1001_0010, // 43
// []int{
// 0, 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},
// []int{1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61},
// },
} {
d := Dict{b: []uint{tc.b}}
for j, r := range tc.ranks {
got := d.select0(r)
if got != tc.want[j] {
t.Errorf("tc: %d, select(%b, %d) = got: %d != want: %d\n", i, tc.b, r, got, tc.want[j])
}
}
}
}