-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid_to_bitmap_map_test.go
109 lines (95 loc) · 2.78 KB
/
id_to_bitmap_map_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
package dm
import (
"fmt"
"git.100tal.com/wangxiao_xesbiz_operation/gently-utils/container/dm/croaring"
"runtime"
"testing"
"time"
)
const MaxId = 600 * 10000
func TestIdToBitmapMem(t *testing.T) {
itb := NewIdToBitmap(5)
for i := 1; i <= MaxId; i++ {
bitmaps := make([]croaring.Bitmap, 0, 10)
for j := 1; j <= 10; j++ {
bitmaps = append(bitmaps, croaring.Bitmap(i*10000+j))
}
itb.Add(uint32(i), bitmaps...)
}
for {
fmt.Println(len(itb.ToArray(1)))
fmt.Println("array", itb.stats)
runtime.GC()
time.Sleep(time.Minute)
}
fmt.Println("over")
}
func TestIdToBitMemRandom(t *testing.T) {
itb := NewIdToBitmap(5)
var k = 30
for i := 1; i <= MaxBinaryId; i++ {
bitmaps := make([]croaring.Bitmap, 0, 10)
for j := 1; j <= k; j++ {
bitmaps = append(bitmaps, croaring.Bitmap(i*10000+j))
}
k--
if k <= 0 {
k = 30
}
itb.Add(uint32(i), bitmaps...)
}
for {
fmt.Println(len(itb.ToArray(1)))
runtime.GC()
time.Sleep(time.Minute)
}
fmt.Println("over")
}
func TestIdToBitmap(t *testing.T) {
check := make(map[uint32]map[croaring.Bitmap]bool)
itb := NewIdToBitmap(5)
for i := 1; i <= MaxId; i++ {
bitmaps := make([]croaring.Bitmap, 0, 10)
for j := 1; j <= 10; j++ {
bitmaps = append(bitmaps, croaring.Bitmap(i*10000+j))
if _, has := check[uint32(i)]; !has {
check[uint32(i)] = make(map[croaring.Bitmap]bool)
}
check[uint32(i)][croaring.Bitmap(i*10000+j)] = true
}
itb.Add(uint32(i), bitmaps...)
}
if stats := itb.GetStats(); stats.Count != MaxId*10 {
t.Error("GetStats count err", stats)
}
for i := 1; i <= MaxId; i++ {
itb.Iterate(uint32(i), func(bitmap croaring.Bitmap) bool {
if _, has := check[uint32(i)][bitmap]; !has {
t.Error("id", i, "check Iterate failed. because", bitmap)
return false
}
return true
})
}
for i := 1; i <= MaxId; i++ {
array := itb.ToArray(uint32(i))
for _, bitmap := range array {
if _, has := check[uint32(i)][bitmap]; !has && len(array) != len(check[uint32(i)]) {
t.Error("id", i, "check ToArray failed. because", bitmap)
}
}
}
for i := 1; i <= MaxId; i++ {
itb.Del(uint32(i))
}
if stats := itb.GetStats(); stats.Count != 0 {
t.Error("GetStats count err", stats)
}
for i := 1; i <= MaxId; i++ {
array := itb.ToArray(50)
if len(array) > 0 {
t.Error("Del 50 failed. because", array)
}
}
t.Log("end")
}