fix and iterator, add some logging, and reenable

This commit is contained in:
Barak Michener 2014-08-12 16:38:10 -04:00
parent 99d44e3228
commit b6d966e9b5
3 changed files with 33 additions and 16 deletions

View file

@ -48,6 +48,7 @@ func (it *And) UID() uint64 {
// Reset all internal iterators // Reset all internal iterators
func (it *And) Reset() { func (it *And) Reset() {
it.result = nil
it.primaryIt.Reset() it.primaryIt.Reset()
for _, sub := range it.internalIterators { for _, sub := range it.internalIterators {
sub.Reset() sub.Reset()
@ -159,7 +160,7 @@ func (it *And) Next() bool {
graph.NextLogIn(it) graph.NextLogIn(it)
for graph.Next(it.primaryIt) { for graph.Next(it.primaryIt) {
curr := it.primaryIt.Result() curr := it.primaryIt.Result()
if it.subItsContain(curr) { if it.subItsContain(curr, nil) {
it.result = curr it.result = curr
return graph.NextLogOut(it, curr, true) return graph.NextLogOut(it, curr, true)
} }
@ -172,22 +173,32 @@ func (it *And) Result() graph.Value {
} }
// Checks a value against the non-primary iterators, in order. // Checks a value against the non-primary iterators, in order.
func (it *And) subItsContain(val graph.Value) bool { func (it *And) subItsContain(val graph.Value, lastResult graph.Value) bool {
var subIsGood = true var subIsGood = true
for _, sub := range it.internalIterators { for i, sub := range it.internalIterators {
subIsGood = sub.Contains(val) subIsGood = sub.Contains(val)
if !subIsGood { if !subIsGood {
if lastResult != nil {
for j := 0; j < i; j++ {
it.internalIterators[j].Contains(lastResult)
}
}
break break
} }
} }
return subIsGood return subIsGood
} }
func (it *And) checkContainsList(val graph.Value) bool { func (it *And) checkContainsList(val graph.Value, lastResult graph.Value) bool {
ok := true ok := true
for _, c := range it.checkList { for i, c := range it.checkList {
ok = c.Contains(val) ok = c.Contains(val)
if !ok { if !ok {
if lastResult != nil {
for j := 0; j < i; j++ {
it.checkList[j].Contains(lastResult)
}
}
break break
} }
} }
@ -200,19 +211,22 @@ func (it *And) checkContainsList(val graph.Value) bool {
// Check a value against the entire iterator, in order. // Check a value against the entire iterator, in order.
func (it *And) Contains(val graph.Value) bool { func (it *And) Contains(val graph.Value) bool {
graph.ContainsLogIn(it, val) graph.ContainsLogIn(it, val)
lastResult := it.result
if it.checkList != nil { if it.checkList != nil {
return it.checkContainsList(val) return it.checkContainsList(val, lastResult)
} }
mainGood := it.primaryIt.Contains(val) mainGood := it.primaryIt.Contains(val)
if !mainGood { if mainGood {
return graph.ContainsLogOut(it, val, false) othersGood := it.subItsContain(val, lastResult)
if othersGood {
it.result = val
return graph.ContainsLogOut(it, val, true)
}
} }
othersGood := it.subItsContain(val) if lastResult != nil {
if !othersGood { it.primaryIt.Contains(lastResult)
return graph.ContainsLogOut(it, val, false)
} }
it.result = val return graph.ContainsLogOut(it, val, false)
return graph.ContainsLogOut(it, val, true)
} }
// Returns the approximate size of the And iterator. Because we're dealing // Returns the approximate size of the And iterator. Because we're dealing

View file

@ -70,7 +70,7 @@ func (it *And) Optimize() (graph.Iterator, bool) {
// now a permutation of itself, but the contents are unchanged. // now a permutation of itself, but the contents are unchanged.
its = optimizeOrder(its) its = optimizeOrder(its)
//its = materializeIts(its) its = materializeIts(its)
// Okay! At this point we have an optimized order. // Okay! At this point we have an optimized order.
@ -327,7 +327,7 @@ func (it *And) Stats() graph.IteratorStats {
} }
} }
return graph.IteratorStats{ return graph.IteratorStats{
ContainsCost: ContainsCost, ContainsCost: ContainsCost * 2,
NextCost: NextCost, NextCost: NextCost,
Size: Size, Size: Size,
} }

View file

@ -179,10 +179,13 @@ func (it *HasA) NextPath() bool {
// //
// The upshot is, the end of NextPath() bubbles up from the bottom of the // The upshot is, the end of NextPath() bubbles up from the bottom of the
// iterator tree up, and we need to respect that. // iterator tree up, and we need to respect that.
glog.V(4).Infoln("HASA", it.UID(), "NextPath")
if it.primaryIt.NextPath() { if it.primaryIt.NextPath() {
return true return true
} }
return it.NextContains() result := it.NextContains()
glog.V(4).Infoln("HASA", it.UID(), "NextPath Returns", result, "")
return result
} }
// Next advances the iterator. This is simpler than Contains. We have a // Next advances the iterator. This is simpler than Contains. We have a