Simplify Nexter interface
This change allows a Nexter to be used in the same manner as a scanner
using a for graph.Next(it) {} construction.
It is important that graph.Next(it) and any associated it.Result() calls
operate on the same iterator.
This commit is contained in:
parent
f8e28e066e
commit
b1a70d99aa
31 changed files with 168 additions and 233 deletions
|
|
@ -151,8 +151,7 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string
|
|||
if ses.doHalt {
|
||||
return nil
|
||||
}
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.Value)
|
||||
|
|
@ -187,11 +186,10 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri
|
|||
if ses.doHalt {
|
||||
return nil
|
||||
}
|
||||
val, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
break
|
||||
}
|
||||
output = append(output, ses.ts.NameOf(val))
|
||||
output = append(output, ses.ts.NameOf(it.Result()))
|
||||
count++
|
||||
if limit >= 0 && count >= limit {
|
||||
break
|
||||
|
|
@ -208,8 +206,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu
|
|||
if ses.doHalt {
|
||||
return
|
||||
}
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.Value)
|
||||
|
|
@ -249,8 +246,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
|||
if ses.doHalt {
|
||||
return
|
||||
}
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.Value)
|
||||
|
|
|
|||
|
|
@ -88,11 +88,7 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) {
|
|||
if glog.V(2) {
|
||||
glog.V(2).Infoln(it.DebugString(0))
|
||||
}
|
||||
for {
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for graph.Next(it) {
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
c <- tags
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ func TestMemstoreBackedSexp(t *testing.T) {
|
|||
if it.Type() != test.typ {
|
||||
t.Errorf("Incorrect type for %s, got:%q expect %q", test.message, it.Type(), test.expect)
|
||||
}
|
||||
got, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
t.Errorf("Failed to %s", test.message)
|
||||
}
|
||||
got := it.Result()
|
||||
if expect := ts.ValueOf(test.expect); got != expect {
|
||||
t.Errorf("Incorrect result for %s, got:%v expect %v", test.message, got, expect)
|
||||
}
|
||||
|
|
@ -88,10 +88,10 @@ func TestTreeConstraintParse(t *testing.T) {
|
|||
if it.Type() != graph.And {
|
||||
t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
|
||||
}
|
||||
out, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
out := it.Result()
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
}
|
||||
|
|
@ -105,8 +105,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
|||
"(:like\n" +
|
||||
"($a (:is :good))))"
|
||||
it := BuildIteratorTreeForQuery(ts, query)
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
tags := make(map[string]graph.Value)
|
||||
|
|
@ -135,15 +134,14 @@ func TestMultipleConstraintParse(t *testing.T) {
|
|||
if it.Type() != graph.And {
|
||||
t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
|
||||
}
|
||||
out, ok := graph.Next(it)
|
||||
if !ok {
|
||||
if !graph.Next(it) {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
out := it.Result()
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
}
|
||||
_, ok = graph.Next(it)
|
||||
if ok {
|
||||
if graph.Next(it) {
|
||||
t.Error("Too many results")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,11 +77,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
|||
fmt.Println(it.DebugString(0))
|
||||
}
|
||||
nResults := 0
|
||||
for {
|
||||
_, ok := graph.Next(it)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for graph.Next(it) {
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
out <- &tags
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue