Address review comments
This commit is contained in:
parent
430ff507f0
commit
5eed4d9667
19 changed files with 125 additions and 139 deletions
|
|
@ -29,8 +29,8 @@ type And struct {
|
|||
primaryIt graph.Iterator
|
||||
checkList []graph.Iterator
|
||||
result graph.Value
|
||||
err error
|
||||
runstats graph.IteratorStats
|
||||
err error
|
||||
}
|
||||
|
||||
// Creates a new And iterator.
|
||||
|
|
@ -154,9 +154,7 @@ func (it *And) Next() bool {
|
|||
return graph.NextLogOut(it, curr, true)
|
||||
}
|
||||
}
|
||||
if err := it.primaryIt.Err(); err != nil {
|
||||
it.err = err
|
||||
}
|
||||
it.err = it.primaryIt.Err()
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
}
|
||||
|
||||
|
|
@ -190,14 +188,26 @@ func (it *And) checkContainsList(val graph.Value, lastResult graph.Value) bool {
|
|||
for i, c := range it.checkList {
|
||||
ok = c.Contains(val)
|
||||
if !ok {
|
||||
if err := c.Err(); err != nil {
|
||||
it.err = err
|
||||
it.err = c.Err()
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if lastResult != nil {
|
||||
for j := 0; j < i; j++ {
|
||||
// TODO(andrew-d): Should this result actually be used?
|
||||
// One of the iterators has determined that this value doesn't
|
||||
// match. However, the iterators that came before in the list
|
||||
// may have returned "ok" to Contains(). We need to set all
|
||||
// the tags back to what the previous result was -- effectively
|
||||
// seeking back exactly one -- so we check all the prior iterators
|
||||
// with the (already verified) result and throw away the result,
|
||||
// which will be 'true'
|
||||
it.checkList[j].Contains(lastResult)
|
||||
|
||||
it.err = it.checkList[j].Err()
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
|
|
@ -254,16 +264,17 @@ func (it *And) NextPath() bool {
|
|||
if it.primaryIt.NextPath() {
|
||||
return true
|
||||
}
|
||||
if err := it.primaryIt.Err(); err != nil {
|
||||
it.err = err
|
||||
it.err = it.primaryIt.Err()
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
for _, sub := range it.internalIterators {
|
||||
if sub.NextPath() {
|
||||
return true
|
||||
}
|
||||
if err := sub.Err(); err != nil {
|
||||
it.err = err
|
||||
|
||||
it.err = sub.Err()
|
||||
if it.err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -275,23 +286,20 @@ func (it *And) cleanUp() {}
|
|||
|
||||
// Close this iterator, and, by extension, close the subiterators.
|
||||
// Close should be idempotent, and it follows that if it's subiterators
|
||||
// follow this contract, the And follows the contract.
|
||||
//
|
||||
// Note: as this potentially involves closing multiple subiterators, only
|
||||
// the first error encountered while closing will be reported (if any).
|
||||
// follow this contract, the And follows the contract. It closes all
|
||||
// subiterators it can, but returns the first error it encounters.
|
||||
func (it *And) Close() error {
|
||||
it.cleanUp()
|
||||
|
||||
var ret error
|
||||
|
||||
ret = it.primaryIt.Close()
|
||||
err := it.primaryIt.Close()
|
||||
for _, sub := range it.internalIterators {
|
||||
if err := sub.Close(); err != nil && ret != nil {
|
||||
ret = err
|
||||
serr := sub.Close()
|
||||
if serr != nil && err == nil {
|
||||
err = serr
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
return err
|
||||
}
|
||||
|
||||
// Register this as an "and" iterator.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue