Enumerate iterator types

This commit is contained in:
kortschak 2014-07-03 09:57:31 +09:30
parent 1f67913ed9
commit cd46452b63
23 changed files with 145 additions and 68 deletions

View file

@ -157,12 +157,21 @@ func (it *Iterator) Size() (int64, bool) {
return it.size, true
}
func (it *Iterator) Type() string {
if it.isAll {
return "all"
}
return "mongo"
var mongoType graph.Type
func init() {
mongoType = graph.Register("mongo")
}
func Type() graph.Type { return mongoType }
func (it *Iterator) Type() graph.Type {
if it.isAll {
return graph.All
}
return mongoType
}
func (it *Iterator) Sorted() bool { return true }
func (it *Iterator) Optimize() (graph.Iterator, bool) { return it, false }

View file

@ -21,7 +21,7 @@ import (
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
switch it.Type() {
case "linksto":
case graph.LinksTo:
return ts.optimizeLinksTo(it.(*iterator.LinksTo))
}
@ -34,7 +34,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
return it, false
}
primary := subs[0]
if primary.Type() == "fixed" {
if primary.Type() == graph.Fixed {
size, _ := primary.Size()
if size == 1 {
val, ok := primary.Next()