-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathoparray_test.go
50 lines (42 loc) · 949 Bytes
/
oparray_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
package skipset
import (
"testing"
"unsafe"
"github.com/zhangyunhao116/fastrand"
)
type dummy struct {
data optionalArray
}
func TestOpArray(t *testing.T) {
n := new(dummy)
n.data.extra = new([op2]unsafe.Pointer)
var array [maxLevel]unsafe.Pointer
for i := 0; i < maxLevel; i++ {
value := unsafe.Pointer(&dummy{})
array[i] = value
n.data.store(i, value)
}
for i := 0; i < maxLevel; i++ {
if array[i] != n.data.load(i) || array[i] != n.data.atomicLoad(i) {
t.Fatal(i, array[i], n.data.load(i))
}
}
for i := 0; i < 1000; i++ {
r := int(fastrand.Uint32n(maxLevel))
value := unsafe.Pointer(&dummy{})
if i%100 == 0 {
value = nil
}
array[r] = value
if fastrand.Uint32n(2) == 0 {
n.data.store(r, value)
} else {
n.data.atomicStore(r, value)
}
}
for i := 0; i < maxLevel; i++ {
if array[i] != n.data.load(i) || array[i] != n.data.atomicLoad(i) {
t.Fatal(i, array[i], n.data.load(i))
}
}
}