-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (67 loc) · 1.29 KB
/
main.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
package main
import (
"fmt"
"math/big"
"github.com/pilosa/pilosa/v2/roaring"
)
func Truncate(rat *big.Rat) *big.Rat {
var z1 big.Int
d := z1.Div(rat.Num(), rat.Denom())
return big.NewRat(d.Int64(), 1)
}
func modl(x *big.Rat) *big.Rat {
return x.Sub(x, Truncate(x))
}
func pi() func() int64 {
x := new(big.Rat)
n := int64(1)
sixteen := new(big.Rat).SetInt64(16)
return func() int64 {
p := big.NewRat((120*n-89)*n+16, (((512*n-1024)*n+712)*n-206)*n+21)
x = modl(p.Add(x.Mul(x, sixteen), p))
n += 1
var a big.Rat
a.Mul(sixteen, x)
var z1 big.Int
d := z1.Div(a.Num(), a.Denom())
return d.Int64()
}
}
func build(n, SHARDWIDTH int) *roaring.Bitmap {
next := pi()
bm := roaring.NewSliceBitmap()
bit := uint64(0)
bits := make([]uint64, 0, SHARDWIDTH)
for i := 0; i < n; i++ {
hexdigit := next()
if hexdigit&1 > 0 {
bits = append(bits, bit)
}
bit++
if hexdigit&2 > 0 {
bits = append(bits, bit)
}
bit++
if hexdigit&4 > 0 {
bits = append(bits, bit)
}
bit++
if hexdigit&8 > 0 {
bits = append(bits, bit)
}
bit++
if bit == uint64(SHARDWIDTH) {
bm.AddN(bits...)
bits = bits[:0]
}
if i%1000 == 0 {
fmt.Println("Processed", i)
}
}
bm.AddN(bits...)
return bm
}
func main() {
bm := build(1048576, 1048576)
fmt.Println("Count", bm.Count())
}