-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoders.go
73 lines (66 loc) · 1.48 KB
/
encoders.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
package redis_bitmap_go
func (mng *RedisBitmapManager) encode() {
redisApi := mng.redisClient
for msg := range storeCh {
it := msg.it
name := msg.name
callback := msg.callback
redisApi.Del(ctx, generateKeyCp(name))
var a []uint32 = nil
var bytes []byte = nil
ps := map[uint32]int{}
collectCh := make(chan *storePartitionDoneMsg)
checkCh := make(chan *storeCheckMsg)
for partition := uint32(1000); it.HasNext(); {
idx := it.Next()
if getPartition(idx) != partition {
msg := &storePartitionMsg{
name: name,
partition: partition,
list: a,
bytes: bytes,
ch: collectCh,
}
storePartitionCh <- msg
a = nil
bytes = nil
}
partition = getPartition(idx)
ps[partition] = 1
if a == nil && bytes == nil {
a = allocList()
} else if len(a) >= 5000 {
bytes = allocBytes()
for _, _idx := range a {
setBit(getOffset(_idx), bytes)
}
err := listBufPool.ReturnObject(ctx, a)
if err != nil {
panic(err)
}
a = nil
}
if a != nil {
a = append(a, idx)
} else {
setBit(getOffset(idx), bytes)
}
if !it.HasNext() {
msg := &storePartitionMsg{
name: name,
partition: partition,
list: a,
bytes: bytes,
ch: collectCh,
}
storePartitionCh <- msg
}
}
go newCollector(name, collectCh, checkCh, redisApi).collect()
checkCh <- &storeCheckMsg{
name: name,
ps: ps,
callback: callback,
}
}
}