Skip to content

Commit

Permalink
iterator: returns correct subiterator slice for empty And; fixes #659
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Dec 19, 2017
1 parent 6e9cf6c commit 36f5da6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions graph/iterator/and.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func (it *And) Clone() graph.Iterator {

// Returns a slice of the subiterators, in order (primary iterator first).
func (it *And) SubIterators() []graph.Iterator {
iters := make([]graph.Iterator, len(it.internalIterators)+1)
iters[0] = it.primaryIt
copy(iters[1:], it.internalIterators)
iters := make([]graph.Iterator, 0, len(it.internalIterators)+1)
if it.primaryIt != nil {
iters = append(iters, it.primaryIt)
}
iters = append(iters, it.internalIterators...)
return iters
}

Expand Down
6 changes: 3 additions & 3 deletions graph/iterator/and_optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (it *And) Optimize() (graph.Iterator, bool) {

// If we can find only one subiterator which is equivalent to this whole and,
// we can replace the And...
out := it.optimizeReplacement(its)
if out != nil {
if out := it.optimizeReplacement(its); out != nil {
// ...Move the tags to the replacement...
moveTagsTo(out, it)
// ...Close everyone except `out`, our replacement...
Expand Down Expand Up @@ -157,7 +156,7 @@ func (it *And) optimizeOrder(its []graph.Iterator) []graph.Iterator {
var (
// bad contains iterators that can't be (efficiently) nexted, such as
// graph.Optional or graph.Not. Separate them out and tack them on at the end.
out, bad []graph.Iterator
bad []graph.Iterator
best graph.Iterator
bestCost = int64(1 << 62)
)
Expand Down Expand Up @@ -200,6 +199,7 @@ func (it *And) optimizeOrder(its []graph.Iterator) []graph.Iterator {
// Contains() order based on probability of getting a false Contains() first is
// useful (fail faster).

var out []graph.Iterator
// Put the best iterator (the one we wish to Next()) at the front...
out = append(out, best)

Expand Down

0 comments on commit 36f5da6

Please sign in to comment.