mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
convert gotos to for loops
This commit is contained in:
parent
8b06ed9594
commit
5b14227e08
1 changed files with 36 additions and 33 deletions
69
executor.go
69
executor.go
|
|
@ -2836,46 +2836,49 @@ func newGroupByIterator(rowIDs []RowIDs, children []*pql.Call, filter *Row, inde
|
|||
// nextAtIdx is a recursive helper method for getting the next row for the field
|
||||
// at index i, and then updating the rows in the "higher" fields if it wraps.
|
||||
func (gbi *groupByIterator) nextAtIdx(i int) {
|
||||
TOP:
|
||||
nr, rowID, wrapped := gbi.rowIters[i].Next()
|
||||
if nr == nil {
|
||||
gbi.done = true
|
||||
return
|
||||
}
|
||||
if wrapped && i != 0 {
|
||||
gbi.nextAtIdx(i - 1)
|
||||
}
|
||||
if i == 0 && gbi.filter != nil {
|
||||
gbi.rows[i].row = nr.Intersect(gbi.filter)
|
||||
} else if i == 0 || i == len(gbi.rows)-1 {
|
||||
gbi.rows[i].row = nr
|
||||
} else {
|
||||
gbi.rows[i].row = nr.Intersect(gbi.rows[i-1].row)
|
||||
}
|
||||
gbi.rows[i].id = rowID
|
||||
// loop until we find a non-empty row. This is an optimization - the loop and if/break can be removed.
|
||||
for {
|
||||
nr, rowID, wrapped := gbi.rowIters[i].Next()
|
||||
if nr == nil {
|
||||
gbi.done = true
|
||||
return
|
||||
}
|
||||
if wrapped && i != 0 {
|
||||
gbi.nextAtIdx(i - 1)
|
||||
}
|
||||
if i == 0 && gbi.filter != nil {
|
||||
gbi.rows[i].row = nr.Intersect(gbi.filter)
|
||||
} else if i == 0 || i == len(gbi.rows)-1 {
|
||||
gbi.rows[i].row = nr
|
||||
} else {
|
||||
gbi.rows[i].row = nr.Intersect(gbi.rows[i-1].row)
|
||||
}
|
||||
gbi.rows[i].id = rowID
|
||||
|
||||
if gbi.rows[i].row.IsEmpty() {
|
||||
goto TOP // I wanted to just call nextAtIdx again, but if a bunch of
|
||||
// rows in a row were 0, I was worried we'd get into a stack
|
||||
// overflow situation
|
||||
if !gbi.rows[i].row.IsEmpty() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Next returns a GroupCount representing the next group by record. When there
|
||||
// are no more records it will return an empty GroupCount and done==true.
|
||||
func (gbi *groupByIterator) Next() (ret GroupCount, done bool) {
|
||||
TOPNEXT:
|
||||
if gbi.done {
|
||||
return ret, true
|
||||
}
|
||||
if len(gbi.rows) == 1 {
|
||||
ret.Count = gbi.rows[len(gbi.rows)-1].row.Count()
|
||||
} else {
|
||||
ret.Count = gbi.rows[len(gbi.rows)-1].row.intersectionCount(gbi.rows[len(gbi.rows)-2].row)
|
||||
}
|
||||
if ret.Count == 0 {
|
||||
gbi.nextAtIdx(len(gbi.rows) - 1)
|
||||
goto TOPNEXT
|
||||
// loop until we find a result with count > 0
|
||||
for {
|
||||
if gbi.done {
|
||||
return ret, true
|
||||
}
|
||||
if len(gbi.rows) == 1 {
|
||||
ret.Count = gbi.rows[len(gbi.rows)-1].row.Count()
|
||||
} else {
|
||||
ret.Count = gbi.rows[len(gbi.rows)-1].row.intersectionCount(gbi.rows[len(gbi.rows)-2].row)
|
||||
}
|
||||
if ret.Count == 0 {
|
||||
gbi.nextAtIdx(len(gbi.rows) - 1)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
ret.Group = make([]FieldRow, len(gbi.rows))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue