generalize Linkage, add relevant comments

This commit is contained in:
Barak Michener 2015-04-19 20:07:14 -04:00
parent 6201e709ef
commit 355c8ee6bc
5 changed files with 33 additions and 18 deletions

View file

@ -34,7 +34,8 @@ type And struct {
qs graph.QuadStore
}
// Creates a new And iterator.
// NewAnd creates an And iterator. `qs` is only required when needing a handle
// for QuadStore-specific optimizations, otherwise nil is acceptable.
func NewAnd(qs graph.QuadStore) *And {
return &And{
uid: NextUID(),

View file

@ -99,10 +99,12 @@ func (it *And) Optimize() (graph.Iterator, bool) {
// Ask the graph.QuadStore if we can be replaced. Often times, this is a great
// optimization opportunity (there's a fixed iterator underneath us, for
// example).
newReplacement, hasOne := it.qs.OptimizeIterator(newAnd)
if hasOne {
newAnd.Close()
return newReplacement, true
if it.qs != nil {
newReplacement, hasOne := it.qs.OptimizeIterator(newAnd)
if hasOne {
newAnd.Close()
return newReplacement, true
}
}
return newAnd, true