Changed recursion into iteration for removedPostings.Next()

This commit is contained in:
Ganesh Vernekar 2018-02-14 19:13:04 +05:30
parent bc49a665d1
commit 0fb73ed622
2 changed files with 45 additions and 24 deletions

View file

@ -445,7 +445,7 @@ func (rp *removedPostings) Next() bool {
rp.rok = rp.remove.Next()
rp.initialized = true
}
for {
if !rp.fok {
return false
}
@ -469,8 +469,7 @@ func (rp *removedPostings) Next() bool {
// Skip the current posting.
rp.fok = rp.full.Next()
}
return rp.Next()
}
}
func (rp *removedPostings) Seek(id uint64) bool {

View file

@ -354,6 +354,28 @@ func TestRemovedPostings(t *testing.T) {
}
func TestRemovedNextStackoverflow(t *testing.T) {
var full []uint64
var remove []uint64
var i uint64
for i = 0; i < 1e7; i++ {
full = append(full, i)
remove = append(remove, i)
}
flp := newListPostings(full)
rlp := newListPostings(remove)
rp := newRemovedPostings(flp, rlp)
gotElem := false
for rp.Next() {
gotElem = true
}
testutil.Ok(t, rp.Err())
testutil.Assert(t, !gotElem, "")
}
func TestRemovedPostingsSeek(t *testing.T) {
var cases = []struct {
a, b []uint64