scorch zap build reuses mem postingsList/Iterator structs
This commit is contained in:
parent
85761c6a57
commit
8c0881eab2
|
@ -33,12 +33,20 @@ type Dictionary struct {
|
||||||
// PostingsList returns the postings list for the specified term
|
// PostingsList returns the postings list for the specified term
|
||||||
func (d *Dictionary) PostingsList(term string,
|
func (d *Dictionary) PostingsList(term string,
|
||||||
except *roaring.Bitmap) (segment.PostingsList, error) {
|
except *roaring.Bitmap) (segment.PostingsList, error) {
|
||||||
return &PostingsList{
|
return d.InitPostingsList(term, except, nil)
|
||||||
dictionary: d,
|
}
|
||||||
term: term,
|
|
||||||
postingsID: d.segment.Dicts[d.fieldID][term],
|
func (d *Dictionary) InitPostingsList(term string, except *roaring.Bitmap,
|
||||||
except: except,
|
prealloc *PostingsList) (*PostingsList, error) {
|
||||||
}, nil
|
rv := prealloc
|
||||||
|
if rv == nil {
|
||||||
|
rv = &PostingsList{}
|
||||||
|
}
|
||||||
|
rv.dictionary = d
|
||||||
|
rv.term = term
|
||||||
|
rv.postingsID = d.segment.Dicts[d.fieldID][term]
|
||||||
|
rv.except = except
|
||||||
|
return rv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterator returns an iterator for this dictionary
|
// Iterator returns an iterator for this dictionary
|
||||||
|
|
|
@ -46,9 +46,16 @@ func (p *PostingsList) Count() uint64 {
|
||||||
|
|
||||||
// Iterator returns an iterator for this postings list
|
// Iterator returns an iterator for this postings list
|
||||||
func (p *PostingsList) Iterator() segment.PostingsIterator {
|
func (p *PostingsList) Iterator() segment.PostingsIterator {
|
||||||
rv := &PostingsIterator{
|
return p.InitIterator(nil)
|
||||||
postings: p,
|
}
|
||||||
|
func (p *PostingsList) InitIterator(prealloc *PostingsIterator) *PostingsIterator {
|
||||||
|
rv := prealloc
|
||||||
|
if rv == nil {
|
||||||
|
rv = &PostingsIterator{postings: p}
|
||||||
|
} else {
|
||||||
|
*rv = PostingsIterator{postings: p}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.postingsID > 0 {
|
if p.postingsID > 0 {
|
||||||
allbits := p.dictionary.segment.Postings[p.postingsID-1]
|
allbits := p.dictionary.segment.Postings[p.postingsID-1]
|
||||||
rv.locations = p.dictionary.segment.PostingsLocs[p.postingsID-1]
|
rv.locations = p.dictionary.segment.PostingsLocs[p.postingsID-1]
|
||||||
|
|
|
@ -532,6 +532,9 @@ func persistDocValues(memSegment *mem.Segment, w *CountHashWriter,
|
||||||
fieldChunkOffsets := make(map[uint16]uint64, len(memSegment.FieldsInv))
|
fieldChunkOffsets := make(map[uint16]uint64, len(memSegment.FieldsInv))
|
||||||
fdvEncoder := newChunkedContentCoder(uint64(chunkFactor), uint64(len(memSegment.Stored)-1))
|
fdvEncoder := newChunkedContentCoder(uint64(chunkFactor), uint64(len(memSegment.Stored)-1))
|
||||||
|
|
||||||
|
var postings *mem.PostingsList
|
||||||
|
var postingsItr *mem.PostingsIterator
|
||||||
|
|
||||||
for fieldID := range memSegment.DocValueFields {
|
for fieldID := range memSegment.DocValueFields {
|
||||||
field := memSegment.FieldsInv[fieldID]
|
field := memSegment.FieldsInv[fieldID]
|
||||||
docTermMap := make(map[uint64][]byte, 0)
|
docTermMap := make(map[uint64][]byte, 0)
|
||||||
|
@ -543,12 +546,13 @@ func persistDocValues(memSegment *mem.Segment, w *CountHashWriter,
|
||||||
dictItr := dict.Iterator()
|
dictItr := dict.Iterator()
|
||||||
next, err := dictItr.Next()
|
next, err := dictItr.Next()
|
||||||
for err == nil && next != nil {
|
for err == nil && next != nil {
|
||||||
postings, err1 := dict.PostingsList(next.Term, nil)
|
var err1 error
|
||||||
|
postings, err1 = dict.(*mem.Dictionary).InitPostingsList(next.Term, nil, postings)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
postingsItr := postings.Iterator()
|
postingsItr = postings.InitIterator(postingsItr)
|
||||||
nextPosting, err2 := postingsItr.Next()
|
nextPosting, err2 := postingsItr.Next()
|
||||||
for err2 == nil && nextPosting != nil {
|
for err2 == nil && nextPosting != nil {
|
||||||
docNum := nextPosting.Number()
|
docNum := nextPosting.Number()
|
||||||
|
|
Loading…
Reference in New Issue