0
0

Merge pull request #679 from steveyen/scorch

scorch optimize zap Count()
This commit is contained in:
Steve Yen 2017-12-19 18:12:43 -08:00 committed by GitHub
commit ed8bbded02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -85,10 +85,15 @@ func (p *PostingsList) Iterator() segment.PostingsIterator {
// Count returns the number of items on this postings list
func (p *PostingsList) Count() uint64 {
if p.postings != nil {
n := p.postings.GetCardinality()
if p.except != nil {
return roaring.AndNot(p.postings, p.except).GetCardinality()
e := p.except.GetCardinality()
if e > n {
e = n
}
return n - e
}
return p.postings.GetCardinality()
return n
}
return 0
}

View File

@ -32,6 +32,7 @@ type SegmentDictionarySnapshot struct {
}
func (s *SegmentDictionarySnapshot) PostingsList(term string, except *roaring.Bitmap) (segment.PostingsList, error) {
// TODO: if except is non-nil, perhaps need to OR it with s.s.deleted?
return s.d.PostingsList(term, s.s.deleted)
}