Intermediate step in removal of Base

We are marking types that will be Nexters and ResultNexters (I want a
better name for this one).
This commit is contained in:
kortschak 2014-07-30 15:21:48 +09:30
parent 375d953d93
commit b498a06a7b
13 changed files with 42 additions and 56 deletions

View file

@ -41,14 +41,12 @@ type Int64 struct {
// Creates a new Int64 with the given range. // Creates a new Int64 with the given range.
func NewInt64(min, max int64) *Int64 { func NewInt64(min, max int64) *Int64 {
all := Int64{ return &Int64{
uid: NextUID(), uid: NextUID(),
min: min, min: min,
max: max, max: max,
at: min, at: min,
} }
BaseInit(&all.Base)
return &all
} }
func (it *Int64) UID() uint64 { func (it *Int64) UID() uint64 {
@ -113,6 +111,10 @@ func (it *Int64) Result() graph.Value {
return it.result return it.result
} }
func (it *Int64) NextResult() bool {
return false
}
// No sub-iterators. // No sub-iterators.
func (it *Int64) SubIterators() []graph.Iterator { func (it *Int64) SubIterators() []graph.Iterator {
return nil return nil

View file

@ -37,12 +37,10 @@ type And struct {
// Creates a new And iterator. // Creates a new And iterator.
func NewAnd() *And { func NewAnd() *And {
and := And{ return &And{
uid: NextUID(), uid: NextUID(),
internalIterators: make([]graph.Iterator, 0, 20), internalIterators: make([]graph.Iterator, 0, 20),
} }
BaseInit(&and.Base)
return &and
} }
func (it *And) UID() uint64 { func (it *And) UID() uint64 {

View file

@ -57,13 +57,11 @@ func newFixed() *Fixed {
// Creates a new Fixed iterator with a custom comparitor. // Creates a new Fixed iterator with a custom comparitor.
func NewFixedIteratorWithCompare(compareFn Equality) *Fixed { func NewFixedIteratorWithCompare(compareFn Equality) *Fixed {
it := Fixed{ return &Fixed{
uid: NextUID(), uid: NextUID(),
values: make([]graph.Value, 0, 20), values: make([]graph.Value, 0, 20),
cmp: compareFn, cmp: compareFn,
} }
BaseInit(&it.Base)
return &it
} }
func (it *Fixed) UID() uint64 { func (it *Fixed) UID() uint64 {
@ -159,6 +157,10 @@ func (it *Fixed) Result() graph.Value {
return it.result return it.result
} }
func (it *Fixed) NextResult() bool {
return false
}
// No sub-iterators. // No sub-iterators.
func (it *Fixed) SubIterators() []graph.Iterator { func (it *Fixed) SubIterators() []graph.Iterator {
return nil return nil

View file

@ -59,14 +59,12 @@ type HasA struct {
// Construct a new HasA iterator, given the triple subiterator, and the triple // Construct a new HasA iterator, given the triple subiterator, and the triple
// direction for which it stands. // direction for which it stands.
func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d graph.Direction) *HasA { func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d graph.Direction) *HasA {
hasa := HasA{ return &HasA{
uid: NextUID(), uid: NextUID(),
ts: ts, ts: ts,
primaryIt: subIt, primaryIt: subIt,
dir: d, dir: d,
} }
BaseInit(&hasa.Base)
return &hasa
} }
func (it *HasA) UID() uint64 { func (it *HasA) UID() uint64 {

View file

@ -33,21 +33,10 @@ func NextUID() uint64 {
// The Base iterator is the iterator other iterators inherit from to get some // The Base iterator is the iterator other iterators inherit from to get some
// default functionality. // default functionality.
type Base struct { 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 // 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. // 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, // It is the empty set. Often times, queries that contain one of these match nothing,

View file

@ -53,15 +53,13 @@ type LinksTo struct {
// Construct a new LinksTo iterator around a direction and a subiterator of // Construct a new LinksTo iterator around a direction and a subiterator of
// nodes. // nodes.
func NewLinksTo(ts graph.TripleStore, it graph.Iterator, d graph.Direction) *LinksTo { func NewLinksTo(ts graph.TripleStore, it graph.Iterator, d graph.Direction) *LinksTo {
lto := LinksTo{ return &LinksTo{
uid: NextUID(), uid: NextUID(),
ts: ts, ts: ts,
primaryIt: it, primaryIt: it,
dir: d, dir: d,
nextIt: &Null{}, nextIt: &Null{},
} }
BaseInit(&lto.Base)
return &lto
} }
func (it *LinksTo) UID() uint64 { func (it *LinksTo) UID() uint64 {

View file

@ -38,7 +38,6 @@ import (
// An optional iterator has the sub-constraint iterator we wish to be optional // An optional iterator has the sub-constraint iterator we wish to be optional
// and whether the last check we received was true or false. // and whether the last check we received was true or false.
type Optional struct { type Optional struct {
Base
uid uint64 uid uint64
tags graph.Tagger tags graph.Tagger
subIt graph.Iterator subIt graph.Iterator
@ -48,14 +47,14 @@ type Optional struct {
// Creates a new optional iterator. // Creates a new optional iterator.
func NewOptional(it graph.Iterator) *Optional { func NewOptional(it graph.Iterator) *Optional {
var o Optional return &Optional{
BaseInit(&o.Base) uid: NextUID(),
o.canNext = false subIt: it,
o.subIt = it }
o.uid = NextUID()
return &o
} }
func (it *Optional) CanNext() bool { return false }
func (it *Optional) UID() uint64 { func (it *Optional) UID() uint64 {
return it.uid return it.uid
} }

View file

@ -40,24 +40,20 @@ type Or struct {
} }
func NewOr() *Or { func NewOr() *Or {
or := Or{ return &Or{
uid: NextUID(), uid: NextUID(),
internalIterators: make([]graph.Iterator, 0, 20), internalIterators: make([]graph.Iterator, 0, 20),
currentIterator: -1, currentIterator: -1,
} }
BaseInit(&or.Base)
return &or
} }
func NewShortCircuitOr() *Or { func NewShortCircuitOr() *Or {
or := Or{ return &Or{
uid: NextUID(), uid: NextUID(),
internalIterators: make([]graph.Iterator, 0, 20), internalIterators: make([]graph.Iterator, 0, 20),
isShortCircuiting: true, isShortCircuiting: true,
currentIterator: -1, currentIterator: -1,
} }
BaseInit(&or.Base)
return &or
} }
func (it *Or) UID() uint64 { func (it *Or) UID() uint64 {

View file

@ -57,15 +57,13 @@ type Comparison struct {
} }
func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.TripleStore) *Comparison { func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.TripleStore) *Comparison {
vc := Comparison{ return &Comparison{
uid: NextUID(), uid: NextUID(),
subIt: sub, subIt: sub,
op: op, op: op,
val: val, val: val,
ts: ts, ts: ts,
} }
BaseInit(&vc.Base)
return &vc
} }
func (it *Comparison) UID() uint64 { func (it *Comparison) UID() uint64 {

View file

@ -53,7 +53,6 @@ func NewAllIterator(prefix string, d graph.Direction, ts *TripleStore) *AllItera
open: true, open: true,
ts: ts, ts: ts,
} }
iterator.BaseInit(&it.Base)
it.iter.Seek(it.prefix) it.iter.Seek(it.prefix)
if !it.iter.Valid() { if !it.iter.Valid() {
@ -130,6 +129,10 @@ func (it *AllIterator) Result() graph.Value {
return it.result return it.result
} }
func (it *AllIterator) NextResult() bool {
return false
}
// No subiterators. // No subiterators.
func (it *AllIterator) SubIterators() []graph.Iterator { func (it *AllIterator) SubIterators() []graph.Iterator {
return nil return nil

View file

@ -62,7 +62,6 @@ func NewIterator(prefix string, d graph.Direction, value graph.Value, ts *Triple
open: true, open: true,
ts: ts, ts: ts,
} }
iterator.BaseInit(&it.Base)
ok := it.iter.Seek(it.nextPrefix) ok := it.iter.Seek(it.nextPrefix)
if !ok { if !ok {
@ -155,6 +154,10 @@ func (it *Iterator) Result() graph.Value {
return it.result return it.result
} }
func (it *Iterator) NextResult() bool {
return false
}
// No subiterators. // No subiterators.
func (it *Iterator) SubIterators() []graph.Iterator { func (it *Iterator) SubIterators() []graph.Iterator {
return nil return nil

View file

@ -56,14 +56,12 @@ func IterateOne(tree *llrb.LLRB, last Int64) Int64 {
} }
func NewLlrbIterator(tree *llrb.LLRB, data string) *Iterator { func NewLlrbIterator(tree *llrb.LLRB, data string) *Iterator {
it := Iterator{ return &Iterator{
uid: iterator.NextUID(), uid: iterator.NextUID(),
tree: tree, tree: tree,
iterLast: Int64(-1), iterLast: Int64(-1),
data: data, data: data,
} }
iterator.BaseInit(&it.Base)
return &it
} }
func (it *Iterator) UID() uint64 { func (it *Iterator) UID() uint64 {
@ -114,6 +112,10 @@ func (it *Iterator) Result() graph.Value {
return it.result return it.result
} }
func (it *Iterator) NextResult() bool {
return false
}
// No subiterators. // No subiterators.
func (it *Iterator) SubIterators() []graph.Iterator { func (it *Iterator) SubIterators() []graph.Iterator {
return nil return nil

View file

@ -64,7 +64,7 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap
return nil return nil
} }
m := Iterator{ return &Iterator{
uid: iterator.NextUID(), uid: iterator.NextUID(),
name: name, name: name,
constraint: constraint, constraint: constraint,
@ -76,9 +76,6 @@ func NewIterator(ts *TripleStore, collection string, d graph.Direction, val grap
hash: val.(string), hash: val.(string),
isAll: false, isAll: false,
} }
iterator.BaseInit(&m.Base)
return &m
} }
func NewAllIterator(ts *TripleStore, collection string) *Iterator { func NewAllIterator(ts *TripleStore, collection string) *Iterator {
@ -89,7 +86,7 @@ func NewAllIterator(ts *TripleStore, collection string) *Iterator {
return nil return nil
} }
m := Iterator{ return &Iterator{
uid: iterator.NextUID(), uid: iterator.NextUID(),
ts: ts, ts: ts,
dir: graph.Any, dir: graph.Any,
@ -100,9 +97,6 @@ func NewAllIterator(ts *TripleStore, collection string) *Iterator {
hash: "", hash: "",
isAll: true, isAll: true,
} }
// FIXME(kortschak) Was there supposed to be a BaseInit call here?
return &m
} }
func (it *Iterator) UID() uint64 { func (it *Iterator) UID() uint64 {
@ -171,6 +165,10 @@ func (it *Iterator) Result() graph.Value {
return it.result return it.result
} }
func (it *Iterator) NextResult() bool {
return false
}
// No subiterators. // No subiterators.
func (it *Iterator) SubIterators() []graph.Iterator { func (it *Iterator) SubIterators() []graph.Iterator {
return nil return nil