From b63faea683e6cbb5d98e64385277c66fe5d2fdd2 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sat, 23 Dec 2017 03:56:40 +0200 Subject: [PATCH] iterator: remove unused equality function for fixed --- graph/bolt/bolt_test.go | 3 +-- graph/bolt/quadstore.go | 15 ++------------- graph/gaedatastore/quadstore.go | 11 ----------- graph/graphmock/graphmock.go | 16 ++++------------ graph/graphtest/graphtest.go | 6 ++---- graph/iterator/and_optimize_test.go | 16 ++++++++-------- graph/iterator/and_test.go | 20 ++++++++++---------- graph/iterator/count_test.go | 4 ++-- graph/iterator/fixed.go | 17 ++++------------- graph/iterator/iterator_test.go | 2 +- graph/iterator/limit_test.go | 2 +- graph/iterator/linksto_test.go | 4 ++-- graph/iterator/not_test.go | 6 +++--- graph/iterator/or_test.go | 12 ++++++------ graph/iterator/query_shape_test.go | 9 +++------ graph/iterator/recursive.go | 8 ++++---- graph/iterator/recursive_test.go | 8 ++++---- graph/iterator/skip_test.go | 2 +- graph/iterator/unique_test.go | 2 +- graph/iterator/value_comparison_test.go | 6 +++--- graph/kv/iterators.go | 4 ---- graph/kv/kvtest/kvtest.go | 2 +- graph/leveldb/leveldb_test.go | 2 +- graph/leveldb/quadstore.go | 11 +---------- graph/memstore/quadstore.go | 4 ---- graph/memstore/quadstore_test.go | 10 +++++----- graph/mongo/quadstore.go | 5 ----- graph/mongo/quadstore_test.go | 8 ++++++-- graph/nosql/quadstore.go | 5 ----- graph/quadstore.go | 3 --- graph/shape/shape.go | 2 +- graph/shape/shape_test.go | 3 --- graph/sql/quadstore.go | 5 ----- internal/gephi/stream.go | 2 +- query/mql/build_iterator.go | 4 ++-- query/sexp/parser.go | 2 +- schema/schema.go | 4 ++-- schema/schema_test.go | 3 ++- 38 files changed, 85 insertions(+), 163 deletions(-) diff --git a/graph/bolt/bolt_test.go b/graph/bolt/bolt_test.go index 61af8bdc8..122bf8322 100644 --- a/graph/bolt/bolt_test.go +++ b/graph/bolt/bolt_test.go @@ -163,8 +163,7 @@ func TestOptimize(t *testing.T) { testutil.MakeWriter(t, qs, opts, graphtest.MakeQuadSet()...) // With an linksto-fixed pair - fixed := qs.FixedIterator() - fixed.Add(qs.ValueOf(quad.Raw("F"))) + fixed := iterator.NewFixed(qs.ValueOf(quad.Raw("F"))) fixed.Tagger().Add("internal") lto := iterator.NewLinksTo(qs, fixed, quad.Object) diff --git a/graph/bolt/quadstore.go b/graph/bolt/quadstore.go index ccfac3622..ae2b7b567 100644 --- a/graph/bolt/quadstore.go +++ b/graph/bolt/quadstore.go @@ -23,10 +23,9 @@ import ( "time" "github.com/boltdb/bolt" - "github.com/cayleygraph/cayley/clog" + "github.com/cayleygraph/cayley/clog" "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/graph/proto" "github.com/cayleygraph/cayley/quad" "github.com/cayleygraph/cayley/quad/pquads" @@ -60,7 +59,7 @@ type Token struct { func (t *Token) IsNode() bool { return t.nodes } func (t *Token) Key() interface{} { - return fmt.Sprint(t.bucket, t.key) + return string(bytes.Join([][]byte{t.bucket, t.key}, []byte{0})) } func clone(b []byte) []byte { @@ -575,13 +574,3 @@ func (qs *QuadStore) QuadDirection(val graph.Value, d quad.Direction) graph.Valu } return qs.ValueOf(qs.Quad(v).Get(d)) } - -func compareTokens(a, b graph.Value) bool { - atok := a.(*Token) - btok := b.(*Token) - return bytes.Equal(atok.key, btok.key) && bytes.Equal(atok.bucket, btok.bucket) -} - -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(compareTokens) -} diff --git a/graph/gaedatastore/quadstore.go b/graph/gaedatastore/quadstore.go index 07a50ca15..17af98994 100644 --- a/graph/gaedatastore/quadstore.go +++ b/graph/gaedatastore/quadstore.go @@ -29,7 +29,6 @@ import ( "github.com/cayleygraph/cayley/graph" "github.com/cayleygraph/cayley/graph/http" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/quad" ) @@ -500,16 +499,6 @@ func (qs *QuadStore) NodeSize() int64 { return foundMetadata.NodeCount } -func compareTokens(a, b graph.Value) bool { - atok := a.(*Token) - btok := b.(*Token) - return atok.Kind == btok.Kind && atok.Hash == btok.Hash -} - -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(compareTokens) -} - func (qs *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { return it, false } diff --git a/graph/graphmock/graphmock.go b/graph/graphmock/graphmock.go index 980729546..39f96a7af 100644 --- a/graph/graphmock/graphmock.go +++ b/graph/graphmock/graphmock.go @@ -89,10 +89,6 @@ func (qs *Oldstore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { return &iterator.Null{}, false } -func (qs *Oldstore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *Oldstore) Close() error { return nil } func (qs *Oldstore) QuadDirection(graph.Value, quad.Direction) graph.Value { @@ -144,16 +140,12 @@ func (qs *Store) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { return &iterator.Null{}, false } -func (qs *Store) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *Store) Close() error { return nil } func (qs *Store) DebugPrint() {} func (qs *Store) QuadIterator(d quad.Direction, i graph.Value) graph.Iterator { - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() v := i.(graph.PreFetchedValue).NameOf() for _, q := range qs.Data { if q.Get(d) == v { @@ -173,15 +165,15 @@ func (qs *Store) NodesAllIterator() graph.Iterator { } } } - fixed := qs.FixedIterator() - for k, _ := range set { + fixed := iterator.NewFixed() + for k := range set { fixed.Add(graph.PreFetched(quad.Raw(k))) } return fixed } func (qs *Store) QuadsAllIterator() graph.Iterator { - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() for _, q := range qs.Data { fixed.Add(quadValue{q}) } diff --git a/graph/graphtest/graphtest.go b/graph/graphtest/graphtest.go index f4ccb66a2..1e25e5a5d 100644 --- a/graph/graphtest/graphtest.go +++ b/graph/graphtest/graphtest.go @@ -690,11 +690,9 @@ func TestIteratorsAndNextResultOrderA(t testing.TB, gen testutil.DatabaseFunc, c } require.Equal(t, sz, qs.Size(), "Incorrect number of quads") - fixed := qs.FixedIterator() - fixed.Add(qs.ValueOf(quad.Raw("C"))) + fixed := iterator.NewFixed(qs.ValueOf(quad.Raw("C"))) - fixed2 := qs.FixedIterator() - fixed2.Add(qs.ValueOf(quad.Raw("follows"))) + fixed2 := iterator.NewFixed(qs.ValueOf(quad.Raw("follows"))) all := qs.NodesAllIterator() diff --git a/graph/iterator/and_optimize_test.go b/graph/iterator/and_optimize_test.go index 80d7e0456..7470c1892 100644 --- a/graph/iterator/and_optimize_test.go +++ b/graph/iterator/and_optimize_test.go @@ -30,10 +30,10 @@ import ( func TestIteratorPromotion(t *testing.T) { qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } all := NewInt64(1, 3, true) - fixed := NewFixed(Identity, Int64Node(3)) + fixed := NewFixed(Int64Node(3)) a := NewAnd(qs, all, fixed) all.Tagger().Add("a") fixed.Tagger().Add("b") @@ -56,7 +56,7 @@ func TestIteratorPromotion(t *testing.T) { func TestNullIteratorAnd(t *testing.T) { qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } all := NewInt64(1, 3, true) null := NewNull() @@ -73,7 +73,7 @@ func TestNullIteratorAnd(t *testing.T) { func TestAllPromotion(t *testing.T) { qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } all := NewInt64(100, 300, true) all.Tagger().Add("good") @@ -105,11 +105,11 @@ func TestAllPromotion(t *testing.T) { func TestReorderWithTag(t *testing.T) { qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } - all := NewFixed(Identity, Int64Node(3)) + all := NewFixed(Int64Node(3)) all.Tagger().Add("good") - all2 := NewFixed(Identity, + all2 := NewFixed( Int64Node(3), Int64Node(4), Int64Node(5), @@ -144,7 +144,7 @@ func TestReorderWithTag(t *testing.T) { func TestAndStatistics(t *testing.T) { qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } all := NewInt64(100, 300, true) all.Tagger().Add("good") diff --git a/graph/iterator/and_test.go b/graph/iterator/and_test.go index c4e370679..50b23981e 100644 --- a/graph/iterator/and_test.go +++ b/graph/iterator/and_test.go @@ -29,9 +29,9 @@ func TestTag(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } - fix1 := NewFixed(Identity, Int64Node(234)) + fix1 := NewFixed(Int64Node(234)) fix1.Tagger().Add("foo") and := NewAnd(qs, fix1) and.Tagger().Add("bar") @@ -65,15 +65,15 @@ func TestAndAndFixedIterators(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } - fix1 := NewFixed(Identity, + fix1 := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), Int64Node(4), ) - fix2 := NewFixed(Identity, + fix2 := NewFixed( Int64Node(3), Int64Node(4), Int64Node(5), @@ -108,15 +108,15 @@ func TestNonOverlappingFixedIterators(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } - fix1 := NewFixed(Identity, + fix1 := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), Int64Node(4), ) - fix2 := NewFixed(Identity, + fix2 := NewFixed( Int64Node(5), Int64Node(6), Int64Node(7), @@ -141,7 +141,7 @@ func TestAllIterators(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } all1 := NewInt64(1, 5, true) all2 := NewInt64(4, 10, true) @@ -164,7 +164,7 @@ func TestAndIteratorErr(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } wantErr := errors.New("unique") allErr := newTestIterator(false, wantErr) diff --git a/graph/iterator/count_test.go b/graph/iterator/count_test.go index 9a569026e..3d42e526b 100644 --- a/graph/iterator/count_test.go +++ b/graph/iterator/count_test.go @@ -11,7 +11,7 @@ import ( func TestCount(t *testing.T) { ctx := context.TODO() - fixed := NewFixed(Identity, + fixed := NewFixed( graph.PreFetched(quad.String("a")), graph.PreFetched(quad.String("b")), graph.PreFetched(quad.String("c")), @@ -27,7 +27,7 @@ func TestCount(t *testing.T) { fixed.Reset() - fixed2 := NewFixed(Identity, + fixed2 := NewFixed( graph.PreFetched(quad.String("b")), graph.PreFetched(quad.String("d")), ) diff --git a/graph/iterator/fixed.go b/graph/iterator/fixed.go index f7436a217..bf7390179 100644 --- a/graph/iterator/fixed.go +++ b/graph/iterator/fixed.go @@ -36,24 +36,14 @@ type Fixed struct { tags graph.Tagger values []graph.Value lastIndex int - cmp Equality result graph.Value } -// Define the signature of an equality function. -type Equality func(a, b graph.Value) bool - -// Define an equality function of purely ==, which works for native types. -func Identity(a, b graph.Value) bool { - return a == b -} - // Creates a new Fixed iterator with a custom comparator. -func NewFixed(cmp Equality, vals ...graph.Value) *Fixed { +func NewFixed(vals ...graph.Value) *Fixed { it := &Fixed{ uid: NextUID(), values: make([]graph.Value, 0, 20), - cmp: cmp, } for _, v := range vals { it.Add(v) @@ -84,7 +74,7 @@ func (it *Fixed) TagResults(dst map[string]graph.Value) { func (it *Fixed) Clone() graph.Iterator { vals := make([]graph.Value, len(it.values)) copy(vals, it.values) - out := NewFixed(it.cmp, vals...) + out := NewFixed(vals...) out.tags.CopyFrom(it) return out } @@ -108,8 +98,9 @@ func (it *Fixed) Contains(ctx context.Context, v graph.Value) bool { // However, for fixed iterators, which are by definition kind of tiny, this // isn't a big issue. graph.ContainsLogIn(it, v) + vk := graph.ToKey(v) for _, x := range it.values { - if it.cmp(x, v) { + if graph.ToKey(x) == vk { it.result = x return graph.ContainsLogOut(it, v, true) } diff --git a/graph/iterator/iterator_test.go b/graph/iterator/iterator_test.go index 21bfded9f..0f3d1445d 100644 --- a/graph/iterator/iterator_test.go +++ b/graph/iterator/iterator_test.go @@ -17,7 +17,7 @@ type testIterator struct { func newTestIterator(next bool, err error) graph.Iterator { return &testIterator{ - Fixed: NewFixed(Identity), + Fixed: NewFixed(), NextVal: next, ErrVal: err, } diff --git a/graph/iterator/limit_test.go b/graph/iterator/limit_test.go index 8fa1cf525..7cf9519b1 100644 --- a/graph/iterator/limit_test.go +++ b/graph/iterator/limit_test.go @@ -10,7 +10,7 @@ import ( func TestLimitIteratorBasics(t *testing.T) { ctx := context.TODO() - allIt := NewFixed(Identity, + allIt := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), diff --git a/graph/iterator/linksto_test.go b/graph/iterator/linksto_test.go index a8a8fbbd3..b3dbb912e 100644 --- a/graph/iterator/linksto_test.go +++ b/graph/iterator/linksto_test.go @@ -27,10 +27,10 @@ func TestLinksTo(t *testing.T) { ctx := context.TODO() qs := &graphmock.Oldstore{ Data: []string{1: "cool"}, - Iter: NewFixed(Identity), + Iter: NewFixed(), } qs.Iter.(*Fixed).Add(Int64Quad(2)) - fixed := NewFixed(Identity) + fixed := NewFixed() val := qs.ValueOf(quad.Raw("cool")) if val.(Int64Node) != 1 { t.Fatalf("Failed to return correct value, got:%v expect:1", val) diff --git a/graph/iterator/not_test.go b/graph/iterator/not_test.go index cb285d01b..79a0e7eb4 100644 --- a/graph/iterator/not_test.go +++ b/graph/iterator/not_test.go @@ -11,14 +11,14 @@ import ( func TestNotIteratorBasics(t *testing.T) { ctx := context.TODO() - allIt := NewFixed(Identity, + allIt := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), Int64Node(4), ) - toComplementIt := NewFixed(Identity, + toComplementIt := NewFixed( Int64Node(2), Int64Node(4), ) @@ -55,7 +55,7 @@ func TestNotIteratorErr(t *testing.T) { wantErr := errors.New("unique") allIt := newTestIterator(false, wantErr) - toComplementIt := NewFixed(Identity) + toComplementIt := NewFixed() not := NewNot(toComplementIt, allIt) diff --git a/graph/iterator/or_test.go b/graph/iterator/or_test.go index a35cea3c7..1925d757d 100644 --- a/graph/iterator/or_test.go +++ b/graph/iterator/or_test.go @@ -36,12 +36,12 @@ func iterated(it graph.Iterator) []int { func TestOrIteratorBasics(t *testing.T) { ctx := context.TODO() or := NewOr() - f1 := NewFixed(Identity, + f1 := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), ) - f2 := NewFixed(Identity, + f2 := NewFixed( Int64Node(3), Int64Node(9), Int64Node(20), @@ -85,12 +85,12 @@ func TestShortCircuitingOrBasics(t *testing.T) { ctx := context.TODO() var or *Or - f1 := NewFixed(Identity, + f1 := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), ) - f2 := NewFixed(Identity, + f2 := NewFixed( Int64Node(3), Int64Node(9), Int64Node(20), @@ -143,7 +143,7 @@ func TestShortCircuitingOrBasics(t *testing.T) { // Check that it pulls the second iterator's numbers if the first is empty. or = NewShortCircuitOr() - or.AddSubIterator(NewFixed(Identity)) + or.AddSubIterator(NewFixed()) or.AddSubIterator(f2) expect = []int{3, 9, 20, 21} for i := 0; i < 2; i++ { @@ -164,7 +164,7 @@ func TestOrIteratorErr(t *testing.T) { wantErr := errors.New("unique") orErr := newTestIterator(false, wantErr) - fix1 := NewFixed(Identity, Int64Node(1)) + fix1 := NewFixed(Int64Node(1)) or := NewOr( fix1, diff --git a/graph/iterator/query_shape_test.go b/graph/iterator/query_shape_test.go index 09cf262e0..35fc1a47f 100644 --- a/graph/iterator/query_shape_test.go +++ b/graph/iterator/query_shape_test.go @@ -27,13 +27,11 @@ import ( func hasaWithTag(qs graph.QuadStore, tag string, target string) *HasA { and := NewAnd(qs) - obj := qs.FixedIterator() - obj.Add(qs.ValueOf(quad.Raw(target))) + obj := NewFixed(qs.ValueOf(quad.Raw(target))) obj.Tagger().Add(tag) and.AddSubIterator(NewLinksTo(qs, obj, quad.Object)) - pred := qs.FixedIterator() - pred.Add(qs.ValueOf(quad.Raw("status"))) + pred := NewFixed(qs.ValueOf(quad.Raw("status"))) and.AddSubIterator(NewLinksTo(qs, pred, quad.Predicate)) return NewHasA(qs, and, quad.Subject) @@ -101,8 +99,7 @@ func TestQueryShape(t *testing.T) { hasa2.Tagger().Add("hasa2") andInternal.AddSubIterator(hasa2) - pred := qs.FixedIterator() - pred.Add(qs.ValueOf(quad.Raw("name"))) + pred := NewFixed(qs.ValueOf(quad.Raw("name"))) and := NewAnd(qs) and.AddSubIterator(NewLinksTo(qs, andInternal, quad.Subject)) diff --git a/graph/iterator/recursive.go b/graph/iterator/recursive.go index ce2e7c818..43e94caca 100644 --- a/graph/iterator/recursive.go +++ b/graph/iterator/recursive.go @@ -53,7 +53,7 @@ func NewRecursive(qs graph.QuadStore, it graph.Iterator, morphism graph.ApplyMor morphism: morphism, seen: make(map[interface{}]seenAt), nextIt: &Null{}, - baseIt: qs.FixedIterator(), + baseIt: NewFixed(), pathMap: make(map[interface{}][]map[string]graph.Value), containsValue: nil, maxDepth: maxDepth, @@ -74,7 +74,7 @@ func (it *Recursive) Reset() { it.containsValue = nil it.pathIndex = 0 it.nextIt = &Null{} - it.baseIt = it.qs.FixedIterator() + it.baseIt = NewFixed() it.depth = 0 } @@ -142,7 +142,7 @@ func (it *Recursive) Next(ctx context.Context) bool { return graph.NextLogOut(it, false) } it.depth++ - it.baseIt = it.qs.FixedIterator() + it.baseIt = NewFixed() for _, x := range it.depthCache { it.baseIt.Add(x) } @@ -248,7 +248,7 @@ func (it *Recursive) Size() (int64, bool) { } func (it *Recursive) Stats() graph.IteratorStats { - base := it.qs.FixedIterator() + base := NewFixed() base.Add(Int64Node(20)) fanoutit := it.morphism(it.qs, base) fanoutStats := fanoutit.Stats() diff --git a/graph/iterator/recursive_test.go b/graph/iterator/recursive_test.go index 77cf93253..062ba24d6 100644 --- a/graph/iterator/recursive_test.go +++ b/graph/iterator/recursive_test.go @@ -28,7 +28,7 @@ import ( func singleHop(pred string) graph.ApplyMorphism { return func(qs graph.QuadStore, it graph.Iterator) graph.Iterator { - fixed := qs.FixedIterator() + fixed := NewFixed() fixed.Add(graph.PreFetched(quad.Raw(pred))) predlto := NewLinksTo(qs, fixed, quad.Predicate) lto := NewLinksTo(qs, it.Clone(), quad.Subject) @@ -54,7 +54,7 @@ var rec_test_qs = &graphmock.Store{ func TestRecursiveNext(t *testing.T) { ctx := context.TODO() qs := rec_test_qs - start := qs.FixedIterator() + start := NewFixed() start.Add(graph.PreFetched(quad.Raw("alice"))) r := NewRecursive(qs, start, singleHop("parent"), 0) expected := []string{"bob", "charlie", "dani", "emily"} @@ -73,7 +73,7 @@ func TestRecursiveNext(t *testing.T) { func TestRecursiveContains(t *testing.T) { ctx := context.TODO() qs := rec_test_qs - start := qs.FixedIterator() + start := NewFixed() start.Add(graph.PreFetched(quad.Raw("alice"))) r := NewRecursive(qs, start, singleHop("parent"), 0) values := []string{"charlie", "bob", "not"} @@ -95,7 +95,7 @@ func TestRecursiveNextPath(t *testing.T) { it := singleHop("follows")(qs, start) and := NewAnd(qs) and.AddSubIterator(it) - fixed := qs.FixedIterator() + fixed := NewFixed() fixed.Add(graph.PreFetched(quad.Raw("alice"))) and.AddSubIterator(fixed) r := NewRecursive(qs, and, singleHop("parent"), 0) diff --git a/graph/iterator/skip_test.go b/graph/iterator/skip_test.go index 450354263..a9aa0194b 100644 --- a/graph/iterator/skip_test.go +++ b/graph/iterator/skip_test.go @@ -10,7 +10,7 @@ import ( func TestSkipIteratorBasics(t *testing.T) { ctx := context.TODO() - allIt := NewFixed(Identity, + allIt := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), diff --git a/graph/iterator/unique_test.go b/graph/iterator/unique_test.go index 9b2100504..9af9193fa 100644 --- a/graph/iterator/unique_test.go +++ b/graph/iterator/unique_test.go @@ -10,7 +10,7 @@ import ( func TestUniqueIteratorBasics(t *testing.T) { ctx := context.TODO() - allIt := NewFixed(Identity, + allIt := NewFixed( Int64Node(1), Int64Node(2), Int64Node(3), diff --git a/graph/iterator/value_comparison_test.go b/graph/iterator/value_comparison_test.go index bdfb56f57..1e01cb75a 100644 --- a/graph/iterator/value_comparison_test.go +++ b/graph/iterator/value_comparison_test.go @@ -33,7 +33,7 @@ var ( ) func simpleFixedIterator() *Fixed { - f := NewFixed(Identity) + f := NewFixed() for i := 0; i < 5; i++ { f.Add(Int64Node(i)) } @@ -41,7 +41,7 @@ func simpleFixedIterator() *Fixed { } func stringFixedIterator() *Fixed { - f := NewFixed(Identity) + f := NewFixed() for _, value := range stringStore.Data { f.Add(graphmock.StringNode(value)) } @@ -49,7 +49,7 @@ func stringFixedIterator() *Fixed { } func mixedFixedIterator() *Fixed { - f := NewFixed(Identity) + f := NewFixed() for i := 0; i < len(mixedStore.Data); i++ { f.Add(Int64Node(i)) } diff --git a/graph/kv/iterators.go b/graph/kv/iterators.go index 3851d4d75..9ecf46efb 100644 --- a/graph/kv/iterators.go +++ b/graph/kv/iterators.go @@ -16,10 +16,6 @@ func (qs *QuadStore) QuadsAllIterator() graph.Iterator { return NewAllIterator(false, qs, nil) } -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *QuadStore) QuadIterator(dir quad.Direction, v graph.Value) graph.Iterator { if v == nil { return iterator.NewNull() diff --git a/graph/kv/kvtest/kvtest.go b/graph/kv/kvtest/kvtest.go index 158de4ced..c1b8da413 100644 --- a/graph/kv/kvtest/kvtest.go +++ b/graph/kv/kvtest/kvtest.go @@ -74,7 +74,7 @@ func testOptimize(t *testing.T, gen DatabaseFunc, _ *Config) { testutil.MakeWriter(t, qs, opts, graphtest.MakeQuadSet()...) // With an linksto-fixed pair - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw("F"))) fixed.Tagger().Add("internal") lto := iterator.NewLinksTo(qs, fixed, quad.Object) diff --git a/graph/leveldb/leveldb_test.go b/graph/leveldb/leveldb_test.go index 4cf747900..df26700d2 100644 --- a/graph/leveldb/leveldb_test.go +++ b/graph/leveldb/leveldb_test.go @@ -165,7 +165,7 @@ func TestOptimize(t *testing.T) { testutil.MakeWriter(t, qs, opts, graphtest.MakeQuadSet()...) // With an linksto-fixed pair - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw("F"))) fixed.Tagger().Add("internal") lto := iterator.NewLinksTo(qs, fixed, quad.Object) diff --git a/graph/leveldb/quadstore.go b/graph/leveldb/quadstore.go index 6eccb1da2..b94e52635 100644 --- a/graph/leveldb/quadstore.go +++ b/graph/leveldb/quadstore.go @@ -20,13 +20,12 @@ import ( "fmt" "time" - "github.com/cayleygraph/cayley/clog" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/util" + "github.com/cayleygraph/cayley/clog" "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/graph/proto" "github.com/cayleygraph/cayley/quad" "github.com/cayleygraph/cayley/quad/pquads" @@ -561,11 +560,3 @@ func (qs *QuadStore) QuadDirection(val graph.Value, d quad.Direction) graph.Valu offset := PositionOf(v[0:2], d, qs) return Token(append([]byte("z"), v[offset:offset+quad.HashSize]...)) } - -func compareBytes(a, b graph.Value) bool { - return bytes.Equal(a.(Token), b.(Token)) -} - -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(compareBytes) -} diff --git a/graph/memstore/quadstore.go b/graph/memstore/quadstore.go index 94c1bc255..936a384ae 100644 --- a/graph/memstore/quadstore.go +++ b/graph/memstore/quadstore.go @@ -489,10 +489,6 @@ func (qs *QuadStore) QuadsAllIterator() graph.Iterator { return newAllIterator(qs, false, qs.last) } -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *QuadStore) QuadDirection(val graph.Value, d quad.Direction) graph.Value { q, ok := qs.quad(val) if !ok { diff --git a/graph/memstore/quadstore_test.go b/graph/memstore/quadstore_test.go index 2e6899c71..6296b26f6 100644 --- a/graph/memstore/quadstore_test.go +++ b/graph/memstore/quadstore_test.go @@ -111,10 +111,10 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) { ctx := context.TODO() qs, _, _ := makeTestStore(simpleGraph) - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw("C"))) - fixed2 := qs.FixedIterator() + fixed2 := iterator.NewFixed() fixed2.Add(qs.ValueOf(quad.Raw("follows"))) all := qs.NodesAllIterator() @@ -159,7 +159,7 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) { func TestLinksToOptimization(t *testing.T) { qs, _, _ := makeTestStore(simpleGraph) - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw("cool"))) lto := iterator.NewLinksTo(qs, fixed, quad.Object) @@ -202,10 +202,10 @@ func TestRemoveQuad(t *testing.T) { t.Error("Couldn't remove quad", err) } - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw("E"))) - fixed2 := qs.FixedIterator() + fixed2 := iterator.NewFixed() fixed2.Add(qs.ValueOf(quad.Raw("follows"))) innerAnd := iterator.NewAnd(qs, diff --git a/graph/mongo/quadstore.go b/graph/mongo/quadstore.go index 9fdac6497..ff87bc2aa 100644 --- a/graph/mongo/quadstore.go +++ b/graph/mongo/quadstore.go @@ -25,7 +25,6 @@ import ( "github.com/cayleygraph/cayley/clog" "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/internal/lru" "github.com/cayleygraph/cayley/quad" "github.com/cayleygraph/cayley/quad/pquads" @@ -533,10 +532,6 @@ func (qs *QuadStore) Size() int64 { return int64(count) } -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *QuadStore) Close() error { qs.db.Session.Close() return nil diff --git a/graph/mongo/quadstore_test.go b/graph/mongo/quadstore_test.go index 9f92fc06c..26adbb897 100644 --- a/graph/mongo/quadstore_test.go +++ b/graph/mongo/quadstore_test.go @@ -8,8 +8,11 @@ import ( "sync" "testing" + "context" + "github.com/cayleygraph/cayley/graph" "github.com/cayleygraph/cayley/graph/graphtest" + "github.com/cayleygraph/cayley/graph/graphtest/testutil" "github.com/cayleygraph/cayley/internal/dock" "github.com/cayleygraph/cayley/quad" ) @@ -62,13 +65,14 @@ func TestMongoConcurrent(t *testing.T) { if testing.Short() { t.SkipNow() } + ctx := context.TODO() qs, opts, closer := makeMongo(t) defer closer() if opts == nil { opts = make(graph.Options) } opts["ignore_duplicate"] = true - qw := graphtest.MakeWriter(t, qs, opts) + qw := testutil.MakeWriter(t, qs, opts) const n = 1000 subjects := make([]string, 0, n/4) @@ -103,7 +107,7 @@ func TestMongoConcurrent(t *testing.T) { } n1 := subjects[rand.Intn(len(subjects))] it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String(n1))) - for it.Next() { + for it.Next(ctx) { q := qs.Quad(it.Result()) _ = q.Subject.Native() _ = q.Predicate.Native() diff --git a/graph/nosql/quadstore.go b/graph/nosql/quadstore.go index 206529a2d..dfd3299f0 100644 --- a/graph/nosql/quadstore.go +++ b/graph/nosql/quadstore.go @@ -22,7 +22,6 @@ import ( "github.com/cayleygraph/cayley/clog" "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/internal/lru" "github.com/cayleygraph/cayley/quad" "github.com/cayleygraph/cayley/quad/pquads" @@ -580,10 +579,6 @@ func (qs *QuadStore) Size() int64 { return count } -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *QuadStore) Close() error { return qs.db.Close() } diff --git a/graph/quadstore.go b/graph/quadstore.go index c3555bf9c..643c963dd 100644 --- a/graph/quadstore.go +++ b/graph/quadstore.go @@ -73,9 +73,6 @@ type QuadStore interface { // Returns the number of quads currently stored. Size() int64 - // Creates a fixed iterator which can compare Values - FixedIterator() FixedIterator - // Optimize an iterator in the context of the quad store. // Suppose we have a better index for the passed tree; this // gives the QuadStore the opportunity to replace it diff --git a/graph/shape/shape.go b/graph/shape/shape.go index 1191ebcea..642afbe9f 100644 --- a/graph/shape/shape.go +++ b/graph/shape/shape.go @@ -674,7 +674,7 @@ func (s *Fixed) Add(v ...graph.Value) { *s = append(*s, v...) } func (s Fixed) BuildIterator(qs graph.QuadStore) graph.Iterator { - it := qs.FixedIterator() + it := iterator.NewFixed() for _, v := range s { if _, ok := v.(quad.Value); ok { panic("quad value in fixed iterator") diff --git a/graph/shape/shape_test.go b/graph/shape/shape_test.go index 6a6250b8c..463bbf8ff 100644 --- a/graph/shape/shape_test.go +++ b/graph/shape/shape_test.go @@ -62,9 +62,6 @@ func (ValLookup) NameOf(_ graph.Value) quad.Value { func (ValLookup) Size() int64 { panic("not implemented") } -func (ValLookup) FixedIterator() graph.FixedIterator { - panic("not implemented") -} func (ValLookup) OptimizeIterator(_ graph.Iterator) (graph.Iterator, bool) { panic("not implemented") } diff --git a/graph/sql/quadstore.go b/graph/sql/quadstore.go index 889290811..ec0d3365e 100644 --- a/graph/sql/quadstore.go +++ b/graph/sql/quadstore.go @@ -10,7 +10,6 @@ import ( "github.com/cayleygraph/cayley/clog" "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/graph/log" "github.com/cayleygraph/cayley/internal/lru" "github.com/cayleygraph/cayley/quad" @@ -641,10 +640,6 @@ func (qs *QuadStore) Size() int64 { return sz } -func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixed(iterator.Identity) -} - func (qs *QuadStore) Close() error { return qs.db.Close() } diff --git a/internal/gephi/stream.go b/internal/gephi/stream.go index ba4cab52b..2697762ef 100644 --- a/internal/gephi/stream.go +++ b/internal/gephi/stream.go @@ -222,7 +222,7 @@ func (s *GraphStreamHandler) serveRawQuads(ctx context.Context, gs *GraphStream, if len(vals) == 0 { return } - fixed := s.QS.FixedIterator() + fixed := iterator.NewFixed() for _, v := range vals { fixed.Add(s.QS.ValueOf(v)) } diff --git a/query/mql/build_iterator.go b/query/mql/build_iterator.go index 17ec9a46b..27942a28e 100644 --- a/query/mql/build_iterator.go +++ b/query/mql/build_iterator.go @@ -26,7 +26,7 @@ import ( ) func (q *Query) buildFixed(s string) graph.Iterator { - f := q.ses.qs.FixedIterator() + f := iterator.NewFixed() f.Add(q.ses.qs.ValueOf(quad.StringToValue(s))) return f } @@ -137,7 +137,7 @@ func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path return nil, err } subAnd := iterator.NewAnd(q.ses.qs) - predFixed := q.ses.qs.FixedIterator() + predFixed := iterator.NewFixed() predFixed.Add(q.ses.qs.ValueOf(quad.StringToValue(pred))) subAnd.AddSubIterator(iterator.NewLinksTo(q.ses.qs, predFixed, quad.Predicate)) if reverse { diff --git a/query/sexp/parser.go b/query/sexp/parser.go index 0dfc2737b..933e1c0e7 100644 --- a/query/sexp/parser.go +++ b/query/sexp/parser.go @@ -197,7 +197,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, qs graph.QuadStore) graph.Itera if tree.Children[0].Children[0].Name == "ColonIdentifier" { n = nodeID[1:] } - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() fixed.Add(qs.ValueOf(quad.Raw(n))) out = fixed } diff --git a/schema/schema.go b/schema/schema.go index 6d486c290..61d6f098c 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -513,7 +513,7 @@ func loadToValue(ctx context.Context, qs graph.QuadStore, dst reflect.Value, dep var sv reflect.Value if recursive { sv = reflect.New(ft).Elem() - sit := qs.FixedIterator() + sit := iterator.NewFixed() sit.Add(fv) err := loadIteratorToDepth(ctx, qs, sv, depth-1, sit) if err == errRequiredFieldIsMissing { @@ -631,7 +631,7 @@ func LoadToDepth(ctx context.Context, qs graph.QuadStore, dst interface{}, depth } var it graph.Iterator if len(ids) != 0 { - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() for _, id := range ids { fixed.Add(qs.ValueOf(id)) } diff --git a/schema/schema_test.go b/schema/schema_test.go index 6906ef03a..76e7ac279 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/cayleygraph/cayley/graph" + "github.com/cayleygraph/cayley/graph/iterator" "github.com/cayleygraph/cayley/graph/memstore" "github.com/cayleygraph/cayley/quad" "github.com/cayleygraph/cayley/schema" @@ -555,7 +556,7 @@ func TestLoadIteratorTo(t *testing.T) { out := reflect.New(reflect.TypeOf(c.expect)) var it graph.Iterator if c.from != nil { - fixed := qs.FixedIterator() + fixed := iterator.NewFixed() for _, id := range c.from { fixed.Add(qs.ValueOf(id)) }