Merge with new Next() interface

This commit is contained in:
Barak Michener 2014-08-10 17:59:09 -04:00
commit a1e5a53dd5
48 changed files with 677 additions and 654 deletions

View file

@ -101,10 +101,10 @@ func (it *AllIterator) Clone() graph.Iterator {
return out
}
func (it *AllIterator) Next() (graph.Value, bool) {
func (it *AllIterator) Next() bool {
if !it.open {
it.result = nil
return nil, false
return false
}
var out []byte
out = make([]byte, len(it.iter.Key()))
@ -115,10 +115,10 @@ func (it *AllIterator) Next() (graph.Value, bool) {
}
if !bytes.HasPrefix(out, it.prefix) {
it.Close()
return nil, false
return false
}
it.result = Token(out)
return it.result, true
return true
}
func (it *AllIterator) ResultTree() *graph.ResultTree {
@ -129,7 +129,7 @@ func (it *AllIterator) Result() graph.Value {
return it.result
}
func (it *AllIterator) NextResult() bool {
func (it *AllIterator) NextPath() bool {
return false
}

View file

@ -125,19 +125,19 @@ func (it *Iterator) isLiveValue(val []byte) bool {
return len(entry.History)%2 != 0
}
func (it *Iterator) Next() (graph.Value, bool) {
func (it *Iterator) Next() bool {
if it.iter == nil {
it.result = nil
return nil, false
return false
}
if !it.open {
it.result = nil
return nil, false
return false
}
if !it.iter.Valid() {
it.result = nil
it.Close()
return nil, false
return false
}
if bytes.HasPrefix(it.iter.Key(), it.nextPrefix) {
if !it.isLiveValue(it.iter.Value()) {
@ -150,11 +150,11 @@ func (it *Iterator) Next() (graph.Value, bool) {
if !ok {
it.Close()
}
return Token(out), true
return true
}
it.Close()
it.result = nil
return nil, false
return false
}
func (it *Iterator) ResultTree() *graph.ResultTree {
@ -165,7 +165,7 @@ func (it *Iterator) Result() graph.Value {
return it.result
}
func (it *Iterator) NextResult() bool {
func (it *Iterator) NextPath() bool {
return false
}

View file

@ -46,12 +46,8 @@ func makeTripleSet() []quad.Quad {
func iteratedTriples(qs graph.TripleStore, it graph.Iterator) []quad.Quad {
var res ordered
for {
val, ok := graph.Next(it)
if !ok {
break
}
res = append(res, qs.Quad(val))
for graph.Next(it) {
res = append(res, qs.Quad(it.Result()))
}
sort.Sort(res)
return res
@ -86,12 +82,8 @@ func (o ordered) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func iteratedNames(qs graph.TripleStore, it graph.Iterator) []string {
var res []string
for {
val, ok := graph.Next(it)
if !ok {
break
}
res = append(res, qs.NameOf(val))
for graph.Next(it) {
res = append(res, qs.NameOf(it.Result()))
}
sort.Strings(res)
return res
@ -271,8 +263,8 @@ func TestIterator(t *testing.T) {
it.Reset()
it = qs.TriplesAllIterator()
edge, _ := graph.Next(it)
triple := qs.Quad(edge)
graph.Next(it)
triple := qs.Quad(it.Result())
set := makeTripleSet()
var ok bool
for _, t := range set {

View file

@ -35,7 +35,7 @@ import (
)
func init() {
graph.RegisterTripleStore("leveldb", newTripleStore, createNewLevelDB)
graph.RegisterTripleStore("leveldb", true, newTripleStore, createNewLevelDB)
}
const (
@ -45,7 +45,7 @@ const (
type Token []byte
func (t Token) Hasher() interface{} {
func (t Token) Key() interface{} {
return string(t)
}

View file

@ -37,10 +37,10 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
if primary.Type() == graph.Fixed {
size, _ := primary.Size()
if size == 1 {
val, ok := graph.Next(primary)
if !ok {
panic("Sizes lie")
if !graph.Next(primary) {
panic("unexpected size during optimize")
}
val := primary.Result()
newIt := ts.TripleIterator(it.Direction(), val)
nt := newIt.Tagger()
nt.CopyFrom(it)