fix overshoot and optimize better
This commit is contained in:
parent
09244ddd38
commit
24f57df859
4 changed files with 21 additions and 10 deletions
|
|
@ -348,7 +348,7 @@ func TestQueries(t *testing.T) {
|
|||
|
||||
// TODO(kortschak) Be more rigorous in this result validation.
|
||||
if len(got) != len(test.expect) {
|
||||
t.Errorf("Unexpected number of results, got:%d expect:%d.", len(got), len(test.expect))
|
||||
t.Errorf("Unexpected number of results, got:%d expect:%d on %s.", len(got), len(test.expect), test.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,11 +154,14 @@ func Next(it Iterator) (Value, bool) {
|
|||
}
|
||||
|
||||
// Height is a convienence function to measure the height of an iterator tree.
|
||||
func Height(it Iterator) int {
|
||||
func Height(it Iterator, until Type) int {
|
||||
if it.Type() == until {
|
||||
return 1
|
||||
}
|
||||
subs := it.SubIterators()
|
||||
maxDepth := 0
|
||||
for _, sub := range subs {
|
||||
h := Height(sub)
|
||||
h := Height(sub, until)
|
||||
if h > maxDepth {
|
||||
maxDepth = h
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ func materializeIts(its []graph.Iterator) []graph.Iterator {
|
|||
for _, it := range its {
|
||||
stats := it.Stats()
|
||||
if stats.Size*stats.NextCost < stats.ContainsCost {
|
||||
if graph.Height(it) > 10 {
|
||||
if graph.Height(it, graph.Materialize) > 10 {
|
||||
out = append(out, NewMaterialize(it))
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,10 +73,16 @@ func (it *Materialize) TagResults(dst map[string]graph.Value) {
|
|||
if !it.hasRun {
|
||||
return
|
||||
}
|
||||
if it.aborted {
|
||||
it.subIt.TagResults(dst)
|
||||
return
|
||||
}
|
||||
if it.lastIndex > len(it.values) {
|
||||
return
|
||||
}
|
||||
for _, tag := range it.tags.Tags() {
|
||||
dst[tag] = it.Result()
|
||||
}
|
||||
|
||||
for tag, value := range it.values[it.lastIndex].tags {
|
||||
dst[tag] = value
|
||||
}
|
||||
|
|
@ -154,6 +160,7 @@ func (it *Materialize) Stats() graph.IteratorStats {
|
|||
}
|
||||
|
||||
func (it *Materialize) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if !it.hasRun {
|
||||
it.materializeSet()
|
||||
}
|
||||
|
|
@ -164,14 +171,15 @@ func (it *Materialize) Next() (graph.Value, bool) {
|
|||
lastVal := it.Result()
|
||||
for it.lastIndex < len(it.values) {
|
||||
it.lastIndex++
|
||||
if it.Result() != lastVal {
|
||||
return it.Result(), true
|
||||
if it.Result() != lastVal && it.Result() != nil {
|
||||
return graph.NextLogOut(it, it.Result(), true)
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
}
|
||||
|
||||
func (it *Materialize) Contains(v graph.Value) bool {
|
||||
graph.ContainsLogIn(it, v)
|
||||
if !it.hasRun {
|
||||
it.materializeSet()
|
||||
}
|
||||
|
|
@ -180,9 +188,9 @@ func (it *Materialize) Contains(v graph.Value) bool {
|
|||
}
|
||||
if i, ok := it.containsMap[v]; ok {
|
||||
it.lastIndex = i
|
||||
return true
|
||||
return graph.ContainsLogOut(it, v, true)
|
||||
}
|
||||
return false
|
||||
return graph.ContainsLogOut(it, v, false)
|
||||
}
|
||||
|
||||
func (it *Materialize) NextResult() bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue