-
Notifications
You must be signed in to change notification settings - Fork 11
/
result_collector.go
60 lines (49 loc) · 1.12 KB
/
result_collector.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
package be_indexer
import "github.com/RoaringBitmap/roaring/roaring64"
type (
ResultCollector interface {
Add(id DocID, conj ConjID)
GetDocIDs() (ids DocIDList)
GetDocIDsInto(ids *DocIDList)
}
// DocIDCollector Default Collector with removing duplicated doc
DocIDCollector struct {
// docBits bitmap hold results docs
docBits *roaring64.Bitmap
}
)
func NewDocIDCollector() *DocIDCollector {
return &DocIDCollector{
docBits: roaring64.New(),
}
}
func (c *DocIDCollector) DocCount() int {
return int(c.docBits.GetCardinality())
}
func (c *DocIDCollector) Reset() {
c.docBits.Clear()
}
func (c *DocIDCollector) Add(docID DocID, _ ConjID) {
c.docBits.Add(uint64(docID))
}
func (c *DocIDCollector) GetDocIDs() (ids DocIDList) {
if c.DocCount() == 0 {
return nil
}
ids = make(DocIDList, 0, c.DocCount())
iter := c.docBits.Iterator()
for iter.HasNext() {
ids = append(ids, DocID(iter.Next()))
}
return ids
}
func (c *DocIDCollector) GetDocIDsInto(ids *DocIDList) {
if c.DocCount() == 0 {
return
}
iter := c.docBits.Iterator()
for iter.HasNext() {
*ids = append(*ids, DocID(iter.Next()))
}
return
}