bounds errors
This commit is contained in:
parent
24f57df859
commit
d102394836
1 changed files with 21 additions and 11 deletions
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/barakmich/glog"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,7 +37,7 @@ type Materialize struct {
|
||||||
tags graph.Tagger
|
tags graph.Tagger
|
||||||
containsMap map[graph.Value]int
|
containsMap map[graph.Value]int
|
||||||
values []result
|
values []result
|
||||||
lastIndex int
|
index int
|
||||||
subIt graph.Iterator
|
subIt graph.Iterator
|
||||||
hasRun bool
|
hasRun bool
|
||||||
aborted bool
|
aborted bool
|
||||||
|
|
@ -46,6 +48,7 @@ func NewMaterialize(sub graph.Iterator) *Materialize {
|
||||||
uid: NextUID(),
|
uid: NextUID(),
|
||||||
containsMap: make(map[graph.Value]int),
|
containsMap: make(map[graph.Value]int),
|
||||||
subIt: sub,
|
subIt: sub,
|
||||||
|
index: -1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +58,7 @@ func (it *Materialize) UID() uint64 {
|
||||||
|
|
||||||
func (it *Materialize) Reset() {
|
func (it *Materialize) Reset() {
|
||||||
it.subIt.Reset()
|
it.subIt.Reset()
|
||||||
it.lastIndex = 0
|
it.index = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Materialize) Close() {
|
func (it *Materialize) Close() {
|
||||||
|
|
@ -77,13 +80,13 @@ func (it *Materialize) TagResults(dst map[string]graph.Value) {
|
||||||
it.subIt.TagResults(dst)
|
it.subIt.TagResults(dst)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if it.lastIndex > len(it.values) {
|
if it.Result() == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, tag := range it.tags.Tags() {
|
for _, tag := range it.tags.Tags() {
|
||||||
dst[tag] = it.Result()
|
dst[tag] = it.Result()
|
||||||
}
|
}
|
||||||
for tag, value := range it.values[it.lastIndex].tags {
|
for tag, value := range it.values[it.index].tags {
|
||||||
dst[tag] = value
|
dst[tag] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,10 +119,16 @@ func (it *Materialize) ResultTree() *graph.ResultTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Materialize) Result() graph.Value {
|
func (it *Materialize) Result() graph.Value {
|
||||||
if it.lastIndex+1 > len(it.values) {
|
if len(it.values) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return it.values[it.lastIndex].id
|
if it.index == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if it.index >= len(it.values) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return it.values[it.index].id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Materialize) SubIterators() []graph.Iterator {
|
func (it *Materialize) SubIterators() []graph.Iterator {
|
||||||
|
|
@ -169,8 +178,8 @@ func (it *Materialize) Next() (graph.Value, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lastVal := it.Result()
|
lastVal := it.Result()
|
||||||
for it.lastIndex < len(it.values) {
|
for it.index < len(it.values) {
|
||||||
it.lastIndex++
|
it.index++
|
||||||
if it.Result() != lastVal && it.Result() != nil {
|
if it.Result() != lastVal && it.Result() != nil {
|
||||||
return graph.NextLogOut(it, it.Result(), true)
|
return graph.NextLogOut(it, it.Result(), true)
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +196,7 @@ func (it *Materialize) Contains(v graph.Value) bool {
|
||||||
return it.subIt.Contains(v)
|
return it.subIt.Contains(v)
|
||||||
}
|
}
|
||||||
if i, ok := it.containsMap[v]; ok {
|
if i, ok := it.containsMap[v]; ok {
|
||||||
it.lastIndex = i
|
it.index = i
|
||||||
return graph.ContainsLogOut(it, v, true)
|
return graph.ContainsLogOut(it, v, true)
|
||||||
}
|
}
|
||||||
return graph.ContainsLogOut(it, v, false)
|
return graph.ContainsLogOut(it, v, false)
|
||||||
|
|
@ -201,12 +210,12 @@ func (it *Materialize) NextResult() bool {
|
||||||
return it.subIt.NextResult()
|
return it.subIt.NextResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
i := it.lastIndex + 1
|
i := it.index + 1
|
||||||
if i == len(it.values) {
|
if i == len(it.values) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if it.Result() == it.values[i].id {
|
if it.Result() == it.values[i].id {
|
||||||
it.lastIndex = i
|
it.index = i
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
@ -239,5 +248,6 @@ func (it *Materialize) materializeSet() {
|
||||||
it.containsMap = nil
|
it.containsMap = nil
|
||||||
it.subIt.Reset()
|
it.subIt.Reset()
|
||||||
}
|
}
|
||||||
|
glog.Infof("Materialization List %d: %#v", it.values)
|
||||||
it.hasRun = true
|
it.hasRun = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue