From b498a06a7b59e1e35af11ce6c66012c44dfbba14 Mon Sep 17 00:00:00 2001 From: kortschak Date: Wed, 30 Jul 2014 15:21:48 +0930 Subject: [PATCH] Intermediate step in removal of Base We are marking types that will be Nexters and ResultNexters (I want a better name for this one). --- graph/iterator/all_iterator.go | 8 +++++--- graph/iterator/and_iterator.go | 4 +--- graph/iterator/fixed_iterator.go | 8 +++++--- graph/iterator/hasa_iterator.go | 4 +--- graph/iterator/iterator.go | 13 +------------ graph/iterator/linksto_iterator.go | 4 +--- graph/iterator/optional_iterator.go | 13 ++++++------- graph/iterator/or_iterator.go | 8 ++------ graph/iterator/value_comparison_iterator.go | 4 +--- graph/leveldb/all_iterator.go | 5 ++++- graph/leveldb/iterator.go | 5 ++++- graph/memstore/iterator.go | 8 +++++--- graph/mongo/iterator.go | 14 ++++++-------- 13 files changed, 42 insertions(+), 56 deletions(-) diff --git a/graph/iterator/all_iterator.go b/graph/iterator/all_iterator.go index 9466cb4..8394a0e 100644 --- a/graph/iterator/all_iterator.go +++ b/graph/iterator/all_iterator.go @@ -41,14 +41,12 @@ type Int64 struct { // Creates a new Int64 with the given range. func NewInt64(min, max int64) *Int64 { - all := Int64{ + return &Int64{ uid: NextUID(), min: min, max: max, at: min, } - BaseInit(&all.Base) - return &all } func (it *Int64) UID() uint64 { @@ -113,6 +111,10 @@ func (it *Int64) Result() graph.Value { return it.result } +func (it *Int64) NextResult() bool { + return false +} + // No sub-iterators. func (it *Int64) SubIterators() []graph.Iterator { return nil diff --git a/graph/iterator/and_iterator.go b/graph/iterator/and_iterator.go index 938d9f8..ba7b70b 100644 --- a/graph/iterator/and_iterator.go +++ b/graph/iterator/and_iterator.go @@ -37,12 +37,10 @@ type And struct { // Creates a new And iterator. func NewAnd() *And { - and := And{ + return &And{ uid: NextUID(), internalIterators: make([]graph.Iterator, 0, 20), } - BaseInit(&and.Base) - return &and } func (it *And) UID() uint64 { diff --git a/graph/iterator/fixed_iterator.go b/graph/iterator/fixed_iterator.go index 82e308a..2caa8e9 100644 --- a/graph/iterator/fixed_iterator.go +++ b/graph/iterator/fixed_iterator.go @@ -57,13 +57,11 @@ func newFixed() *Fixed { // Creates a new Fixed iterator with a custom comparitor. func NewFixedIteratorWithCompare(compareFn Equality) *Fixed { - it := Fixed{ + return &Fixed{ uid: NextUID(), values: make([]graph.Value, 0, 20), cmp: compareFn, } - BaseInit(&it.Base) - return &it } func (it *Fixed) UID() uint64 { @@ -159,6 +157,10 @@ func (it *Fixed) Result() graph.Value { return it.result } +func (it *Fixed) NextResult() bool { + return false +} + // No sub-iterators. func (it *Fixed) SubIterators() []graph.Iterator { return nil diff --git a/graph/iterator/hasa_iterator.go b/graph/iterator/hasa_iterator.go index ea9d2cc..8d9ab46 100644 --- a/graph/iterator/hasa_iterator.go +++ b/graph/iterator/hasa_iterator.go @@ -59,14 +59,12 @@ type HasA struct { // Construct a new HasA iterator, given the triple subiterator, and the triple // direction for which it stands. func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d graph.Direction) *HasA { - hasa := HasA{ + return &HasA{ uid: NextUID(), ts: ts, primaryIt: subIt, dir: d, } - BaseInit(&hasa.Base) - return &hasa } func (it *HasA) UID() uint64 { diff --git a/graph/iterator/iterator.go b/graph/iterator/iterator.go index cb06965..e290dc3 100644 --- a/graph/iterator/iterator.go +++ b/graph/iterator/iterator.go @@ -33,21 +33,10 @@ func NextUID() uint64 { // The Base iterator is the iterator other iterators inherit from to get some // default functionality. type Base struct { - canNext bool -} - -// Called by subclases. -func BaseInit(it *Base) { - // Your basic iterator is nextable - it.canNext = true -} - -func (it *Base) NextResult() bool { - return false } // Accessor -func (it *Base) CanNext() bool { return it.canNext } +func (it *Base) CanNext() bool { return true } // Here we define the simplest iterator -- the Null iterator. It contains nothing. // It is the empty set. Often times, queries that contain one of these match nothing, diff --git a/graph/iterator/linksto_iterator.go b/graph/iterator/linksto_iterator.go index 80071c4..fa7cf29 100644 --- a/graph/iterator/linksto_iterator.go +++ b/graph/iterator/linksto_iterator.go @@ -53,15 +53,13 @@ type LinksTo struct { // Construct a new LinksTo iterator around a direction and a subiterator of // nodes. func NewLinksTo(ts graph.TripleStore, it graph.Iterator, d graph.Direction) *LinksTo { - lto := LinksTo{ + return &LinksTo{ uid: NextUID(), ts: ts, primaryIt: it, dir: d, nextIt: &Null{}, } - BaseInit(<o.Base) - return <o } func (it *LinksTo) UID() uint64 { diff --git a/graph/iterator/optional_iterator.go b/graph/iterator/optional_iterator.go index e87549b..7b9435f 100644 --- a/graph/iterator/optional_iterator.go +++ b/graph/iterator/optional_iterator.go @@ -38,7 +38,6 @@ import ( // An optional iterator has the sub-constraint iterator we wish to be optional // and whether the last check we received was true or false. type Optional struct { - Base uid uint64 tags graph.Tagger subIt graph.Iterator @@ -48,14 +47,14 @@ type Optional struct { // Creates a new optional iterator. func NewOptional(it graph.Iterator) *Optional { - var o Optional - BaseInit(&o.Base) - o.canNext = false - o.subIt = it - o.uid = NextUID() - return &o + return &Optional{ + uid: NextUID(), + subIt: it, + } } +func (it *Optional) CanNext() bool { return false } + func (it *Optional) UID() uint64 { return it.uid } diff --git a/graph/iterator/or_iterator.go b/graph/iterator/or_iterator.go index 20318bf..db323ed 100644 --- a/graph/iterator/or_iterator.go +++ b/graph/iterator/or_iterator.go @@ -40,24 +40,20 @@ type Or struct { } func NewOr() *Or { - or := Or{ + return &Or{ uid: NextUID(), internalIterators: make([]graph.Iterator, 0, 20), currentIterator: -1, } - BaseInit(&or.Base) - return &or } func NewShortCircuitOr() *Or { - or := Or{ + return &Or{ uid: NextUID(), internalIterators: make([]graph.Iterator, 0, 20), isShortCircuiting: true, currentIterator: -1, } - BaseInit(&or.Base) - return &or } func (it *Or) UID() uint64 { diff --git a/graph/iterator/value_comparison_iterator.go b/graph/iterator/value_comparison_iterator.go index 6dfd7c5..ab5e698 100644 --- a/graph/iterator/value_comparison_iterator.go +++ b/graph/iterator/value_comparison_iterator.go @@ -57,15 +57,13 @@ type Comparison struct { } func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.TripleStore) *Comparison { - vc := Comparison{ + return &Comparison{ uid: NextUID(), subIt: sub, op: op, val: val, ts: ts, } - BaseInit(&vc.Base) - return &vc } func (it *Comparison) UID() uint64 { diff --git a/graph/leveldb/all_iterator.go b/graph/leveldb/all_iterator.go index 27cb144..673fbb9 100644 --- a/graph/leveldb/all_iterator.go +++ b/graph/leveldb/all_iterator.go @@ -53,7 +53,6 @@ func NewAllIterator(prefix string, d graph.Direction, ts *TripleStore) *AllItera open: true, ts: ts, } - iterator.BaseInit(&it.Base) it.iter.Seek(it.prefix) if !it.iter.Valid() { @@ -130,6 +129,10 @@ func (it *AllIterator) Result() graph.Value { return it.result } +func (it *AllIterator) NextResult() bool { + return false +} + // No subiterators. func (it *AllIterator) SubIterators() []graph.Iterator { return nil diff --git a/graph/leveldb/iterator.go b/graph/leveldb/iterator.go index 1b6771e..9f9b0bf 100644 --- a/graph/leveldb/iterator.go +++ b/graph/leveldb/iterator.go @@ -62,7 +62,6 @@ func NewIterator(prefix string, d graph.Direction, value graph.Value, ts *Triple open: true, ts: ts, } - iterator.BaseInit(&it.Base) ok := it.iter.Seek(it.nextPrefix) if !ok { @@ -155,6 +154,10 @@ 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 diff --git a/graph/memstore/iterator.go b/graph/memstore/iterator.go index be6d1ff..4be57db 100644 --- a/graph/memstore/iterator.go +++ b/graph/memstore/iterator.go @@ -56,14 +56,12 @@ func IterateOne(tree *llrb.LLRB, last Int64) Int64 { } func NewLlrbIterator(tree *llrb.LLRB, data string) *Iterator { - it := Iterator{ + return &Iterator{ uid: iterator.NextUID(), tree: tree, iterLast: Int64(-1), data: data, } - iterator.BaseInit(&it.Base) - return &it } func (it *Iterator) UID() uint64 { @@ -114,6 +112,10 @@ 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 diff --git a/graph/mongo/iterator.go b/graph/mongo/iterator.go index ab752ef..3389e9f 100644 --- a/graph/mongo/iterator.go +++ b/graph/mongo/iterator.go @@ -64,7 +64,7 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap return nil } - m := Iterator{ + return &Iterator{ uid: iterator.NextUID(), name: name, constraint: constraint, @@ -76,9 +76,6 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap hash: val.(string), isAll: false, } - iterator.BaseInit(&m.Base) - - return &m } func NewAllIterator(ts *TripleStore, collection string) *Iterator { @@ -89,7 +86,7 @@ func NewAllIterator(ts *TripleStore, collection string) *Iterator { return nil } - m := Iterator{ + return &Iterator{ uid: iterator.NextUID(), ts: ts, dir: graph.Any, @@ -100,9 +97,6 @@ func NewAllIterator(ts *TripleStore, collection string) *Iterator { hash: "", isAll: true, } - // FIXME(kortschak) Was there supposed to be a BaseInit call here? - - return &m } func (it *Iterator) UID() uint64 { @@ -171,6 +165,10 @@ 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