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.
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

View file

@ -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 {

View file

@ -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

View file

@ -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 {

View file

@ -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,

View file

@ -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(&lto.Base)
return &lto
}
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
// 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
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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