-
Notifications
You must be signed in to change notification settings - Fork 3
/
interests.go
66 lines (55 loc) · 1.16 KB
/
interests.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
package main
import (
"math/bits"
"github.com/funny-falcon/highloadcup2018/bitmap3"
)
type InterestBlock [16]uint8
type InterestMask [2]uint64
var Interests = make([]InterestMask, Init)
func GetInterest(i int32) *InterestMask {
return &Interests[i]
}
func (bl *InterestBlock) Set(ix uint8) {
for j, intr := range bl {
if intr == uint8(ix) {
return
}
if intr == 0 {
bl[j] = uint8(ix)
return
}
}
panic("interests overflow")
}
func (bl *InterestMask) Set(ix uint8) {
bitmap3.Set(bl[:], int32(ix))
}
func SetInterest(i int32, ix uint8) {
bitmap3.Set(Interests[i][:], int32(ix))
}
func SetInterests(i int32, b InterestMask) {
Interests[i] = b
}
/*
func (i *InterestBlock) Mask() InterestMask {
var mi InterestMask
for _, intr := range i {
bitmap3.Set(mi[:], int32(intr))
}
mi[0] &^= 1
return mi
}
*/
func (mi InterestMask) Unroll(f func(int32)) {
var un bitmap3.Unrolled
for _, ix := range bitmap3.Unroll(mi[0], 0, &un) {
f(ix)
}
for _, ix := range bitmap3.Unroll(mi[1], 64, &un) {
f(ix)
}
}
func (mi InterestMask) IntersectCount(mo InterestMask) uint32 {
return uint32(bits.OnesCount64(mi[0]&mo[0]) +
bits.OnesCount64(mi[1]&mo[1]))
}