-
Notifications
You must be signed in to change notification settings - Fork 3
/
dense_test.go
78 lines (71 loc) · 1.28 KB
/
dense_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
package hll
import (
"log"
"math/rand"
"testing"
)
func TestVerifyDense(t *testing.T) {
for p := 4; p < 26; p++ {
s, err := DenseSizeByP(p)
if err != nil {
log.Panicln(err)
}
h := make(Dense, s)
if h.IsValid() != nil {
t.Fatal(h.IsValid())
}
}
}
func BenchmarkAddDense(b *testing.B) {
s, _ := DenseSizeByP(14)
h := make(Dense, s)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i <= b.N; i++ {
h.Add(uint64(i))
}
}
func BenchmarkEstimateDense(b *testing.B) {
s, _ := DenseSizeByP(14)
h := make(Dense, s)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i <= b.N; i++ {
h.EstimateCardinality()
}
}
func BenchmarkMergeDense(b *testing.B) {
s, _ := DenseSizeByP(14)
h := make(Dense, s)
g := make(Dense, s)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i <= b.N; i++ {
h.Merge(g)
}
}
func TestGetSet(t *testing.T) {
for p := 4; p <= 25; p++ {
max := 1 << byte(p)
m := map[int]byte{}
s, err := DenseSizeByP(p)
if err != nil {
panic(p)
}
h := make(Dense, s)
for i := 0; i < 100000; i++ {
r := byte(rand.Intn(256) & 63)
idx := i % max
h.set(idx, r)
if h.get(idx) != r {
t.Fatal(idx, r, h.get(idx))
}
m[idx] = r
}
for idx := 0; idx < max; idx++ {
if m[idx] != h.get(idx) {
t.Fatal(idx, m[idx], h.get(idx))
}
}
}
}