Sync iteration calls to Nexter interface changes

This commit is contained in:
kortschak 2014-08-07 07:07:45 +09:30
parent 62785d25c2
commit 191244c40e

View file

@ -32,6 +32,10 @@ type result struct {
tags map[string]graph.Value tags map[string]graph.Value
} }
// Keyer provides a method for comparing types that are not otherwise comparable.
// The Key method must return a dynamic type that is comparable according to the
// Go language specification. The returned value must be unique for each receiver
// value.
type Keyer interface { type Keyer interface {
Key() interface{} Key() interface{}
} }
@ -179,7 +183,7 @@ func (it *Materialize) Stats() graph.IteratorStats {
} }
} }
func (it *Materialize) Next() (graph.Value, bool) { func (it *Materialize) Next() bool {
graph.NextLogIn(it) graph.NextLogIn(it)
if !it.hasRun { if !it.hasRun {
it.materializeSet() it.materializeSet()
@ -216,12 +220,12 @@ func (it *Materialize) Contains(v graph.Value) bool {
return graph.ContainsLogOut(it, v, false) return graph.ContainsLogOut(it, v, false)
} }
func (it *Materialize) NextResult() bool { func (it *Materialize) NextPath() bool {
if !it.hasRun { if !it.hasRun {
it.materializeSet() it.materializeSet()
} }
if it.aborted { if it.aborted {
return it.subIt.NextResult() return it.subIt.NextPath()
} }
it.subindex++ it.subindex++
@ -235,16 +239,13 @@ func (it *Materialize) NextResult() bool {
func (it *Materialize) materializeSet() { func (it *Materialize) materializeSet() {
i := 0 i := 0
for { for graph.Next(it.subIt) {
id, ok := graph.Next(it.subIt) i++
if !ok {
break
}
i += 1
if i > abortMaterializeAt { if i > abortMaterializeAt {
it.aborted = true it.aborted = true
break break
} }
id := it.subIt.Result()
val := id val := id
if h, ok := id.(Keyer); ok { if h, ok := id.(Keyer); ok {
val = h.Key() val = h.Key()
@ -257,7 +258,7 @@ func (it *Materialize) materializeSet() {
tags := make(map[string]graph.Value) tags := make(map[string]graph.Value)
it.subIt.TagResults(tags) it.subIt.TagResults(tags)
it.values[index] = append(it.values[index], result{id: id, tags: tags}) it.values[index] = append(it.values[index], result{id: id, tags: tags})
for it.subIt.NextResult() == true { for it.subIt.NextPath() {
tags := make(map[string]graph.Value) tags := make(map[string]graph.Value)
it.subIt.TagResults(tags) it.subIt.TagResults(tags)
it.values[index] = append(it.values[index], result{id: id, tags: tags}) it.values[index] = append(it.values[index], result{id: id, tags: tags})