Merge branch 'declassify' into tip
Conflicts: graph/iterator/hasa_iterator.go graph/iterator/linksto_iterator.go graph/iterator/query_shape_test.go graph/leveldb/all_iterator.go graph/leveldb/iterator.go graph/leveldb/leveldb_test.go graph/memstore/triplestore_test.go graph/mongo/iterator.go
This commit is contained in:
commit
2dbbd17fe1
34 changed files with 823 additions and 457 deletions
|
|
@ -31,6 +31,11 @@ func NewMemstoreAllIterator(ts *TripleStore) *AllIterator {
|
|||
return &out
|
||||
}
|
||||
|
||||
// No subiterators.
|
||||
func (it *AllIterator) SubIterators() []graph.Iterator {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (it *AllIterator) Next() (graph.Value, bool) {
|
||||
next, out := it.Int64.Next()
|
||||
if !out {
|
||||
|
|
@ -41,6 +46,5 @@ func (it *AllIterator) Next() (graph.Value, bool) {
|
|||
if !ok {
|
||||
return it.Next()
|
||||
}
|
||||
it.Last = next
|
||||
return next, out
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@ import (
|
|||
)
|
||||
|
||||
type Iterator struct {
|
||||
iterator.Base
|
||||
uid uint64
|
||||
tags graph.Tagger
|
||||
tree *llrb.LLRB
|
||||
data string
|
||||
isRunning bool
|
||||
iterLast Int64
|
||||
result graph.Value
|
||||
}
|
||||
|
||||
type Int64 int64
|
||||
|
|
@ -53,34 +55,69 @@ func IterateOne(tree *llrb.LLRB, last Int64) Int64 {
|
|||
}
|
||||
|
||||
func NewLlrbIterator(tree *llrb.LLRB, data string) *Iterator {
|
||||
var it Iterator
|
||||
iterator.BaseInit(&it.Base)
|
||||
it.tree = tree
|
||||
it.iterLast = Int64(-1)
|
||||
it.data = data
|
||||
return &it
|
||||
return &Iterator{
|
||||
uid: iterator.NextUID(),
|
||||
tree: tree,
|
||||
iterLast: Int64(-1),
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (it *Iterator) UID() uint64 {
|
||||
return it.uid
|
||||
}
|
||||
|
||||
func (it *Iterator) Reset() {
|
||||
it.iterLast = Int64(-1)
|
||||
}
|
||||
|
||||
func (it *Iterator) Tagger() *graph.Tagger {
|
||||
return &it.tags
|
||||
}
|
||||
|
||||
func (it *Iterator) TagResults(dst map[string]graph.Value) {
|
||||
for _, tag := range it.tags.Tags() {
|
||||
dst[tag] = it.Result()
|
||||
}
|
||||
|
||||
for tag, value := range it.tags.Fixed() {
|
||||
dst[tag] = value
|
||||
}
|
||||
}
|
||||
|
||||
func (it *Iterator) Clone() graph.Iterator {
|
||||
var new_it = NewLlrbIterator(it.tree, it.data)
|
||||
new_it.CopyTagsFrom(it)
|
||||
return new_it
|
||||
m := NewLlrbIterator(it.tree, it.data)
|
||||
m.tags.CopyFrom(it)
|
||||
return m
|
||||
}
|
||||
|
||||
func (it *Iterator) Close() {}
|
||||
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if it.tree.Max() == nil || it.Last == int64(it.tree.Max().(Int64)) {
|
||||
if it.tree.Max() == nil || it.result == int64(it.tree.Max().(Int64)) {
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
}
|
||||
it.iterLast = IterateOne(it.tree, it.iterLast)
|
||||
it.Last = int64(it.iterLast)
|
||||
return graph.NextLogOut(it, it.Last, true)
|
||||
it.result = int64(it.iterLast)
|
||||
return graph.NextLogOut(it, it.result, true)
|
||||
}
|
||||
|
||||
func (it *Iterator) ResultTree() *graph.ResultTree {
|
||||
return graph.NewResultTree(it.Result())
|
||||
}
|
||||
|
||||
func (it *Iterator) Result() graph.Value {
|
||||
return it.result
|
||||
}
|
||||
|
||||
func (it *Iterator) NextResult() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// No subiterators.
|
||||
func (it *Iterator) SubIterators() []graph.Iterator {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (it *Iterator) Size() (int64, bool) {
|
||||
|
|
@ -90,7 +127,7 @@ func (it *Iterator) Size() (int64, bool) {
|
|||
func (it *Iterator) Check(v graph.Value) bool {
|
||||
graph.CheckLogIn(it, v)
|
||||
if it.tree.Has(Int64(v.(int64))) {
|
||||
it.Last = v
|
||||
it.result = v
|
||||
return graph.CheckLogOut(it, v, true)
|
||||
}
|
||||
return graph.CheckLogOut(it, v, false)
|
||||
|
|
@ -98,7 +135,7 @@ func (it *Iterator) Check(v graph.Value) bool {
|
|||
|
||||
func (it *Iterator) DebugString(indent int) string {
|
||||
size, _ := it.Size()
|
||||
return fmt.Sprintf("%s(%s tags:%s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.Tags(), size, it.data)
|
||||
return fmt.Sprintf("%s(%s tags:%s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.tags.Tags(), size, it.data)
|
||||
}
|
||||
|
||||
var memType graph.Type
|
||||
|
|
|
|||
|
|
@ -37,14 +37,15 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if primary.Type() == graph.Fixed {
|
||||
size, _ := primary.Size()
|
||||
if size == 1 {
|
||||
val, ok := primary.Next()
|
||||
val, ok := graph.Next(primary)
|
||||
if !ok {
|
||||
panic("Sizes lie")
|
||||
}
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
newIt.CopyTagsFrom(it)
|
||||
for _, tag := range primary.Tags() {
|
||||
newIt.AddFixedTag(tag, val)
|
||||
nt := newIt.Tagger()
|
||||
nt.CopyFrom(it)
|
||||
for _, tag := range primary.Tagger().Tags() {
|
||||
nt.AddFixed(tag, val)
|
||||
}
|
||||
return newIt, true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
"github.com/google/cayley/graph/iterator"
|
||||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
|
@ -150,7 +151,7 @@ func TestLinksToOptimization(t *testing.T) {
|
|||
fixed.Add(ts.ValueOf("cool"))
|
||||
|
||||
lto := iterator.NewLinksTo(ts, fixed, quad.Object)
|
||||
lto.AddTag("foo")
|
||||
lto.Tagger().Add("foo")
|
||||
|
||||
newIt, changed := lto.Optimize()
|
||||
if !changed {
|
||||
|
|
@ -165,7 +166,8 @@ func TestLinksToOptimization(t *testing.T) {
|
|||
if v_clone.DebugString(0) != v.DebugString(0) {
|
||||
t.Fatal("Wrong iterator. Got ", v_clone.DebugString(0))
|
||||
}
|
||||
if len(v_clone.Tags()) < 1 || v_clone.Tags()[0] != "foo" {
|
||||
vt := v_clone.Tagger()
|
||||
if len(vt.Tags()) < 1 || vt.Tags()[0] != "foo" {
|
||||
t.Fatal("Tag on LinksTo did not persist")
|
||||
}
|
||||
}
|
||||
|
|
@ -188,7 +190,7 @@ func TestRemoveTriple(t *testing.T) {
|
|||
hasa := iterator.NewHasA(ts, innerAnd, quad.Object)
|
||||
|
||||
newIt, _ := hasa.Optimize()
|
||||
_, ok := newIt.Next()
|
||||
_, ok := graph.Next(newIt)
|
||||
if ok {
|
||||
t.Error("E should not have any followers.")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue