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

@ -118,8 +118,8 @@ func (it *AllIterator) DebugString(indent int) string {
return fmt.Sprintf("%s(%s tags: %v leveldb size:%d %s %p)", strings.Repeat(" ", indent), it.Type(), it.Tags(), size, it.dir, it)
}
func (it *AllIterator) Type() string { return "all" }
func (it *AllIterator) Sorted() bool { return false }
func (it *AllIterator) Type() graph.Type { return graph.All }
func (it *AllIterator) Sorted() bool { return false }
func (it *AllIterator) Optimize() (graph.Iterator, bool) {
return it, false

View file

@ -195,8 +195,16 @@ func (it *Iterator) DebugString(indent int) string {
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.UID(), it.Tags(), it.dir, size, it.ts.NameOf(it.checkId))
}
func (it *Iterator) Type() string { return "leveldb" }
func (it *Iterator) Sorted() bool { return false }
var levelDBType graph.Type
func init() {
levelDBType = graph.Register("leveldb")
}
func Type() graph.Type { return levelDBType }
func (it *Iterator) Type() graph.Type { return levelDBType }
func (it *Iterator) Sorted() bool { return false }
func (it *Iterator) Optimize() (graph.Iterator, bool) {
return it, false

View file

@ -160,7 +160,7 @@ func TestIterator(t *testing.T) {
size, accurate := it.Size()
So(size, ShouldBeBetween, 0, 20)
So(accurate, ShouldBeFalse)
So(it.Type(), ShouldEqual, "all")
So(it.Type(), ShouldEqual, graph.All)
re_it, ok := it.Optimize()
So(ok, ShouldBeFalse)
So(re_it, ShouldPointTo, it)
@ -209,7 +209,7 @@ func TestIterator(t *testing.T) {
size, accurate := it.Size()
So(size, ShouldBeBetween, 0, 20)
So(accurate, ShouldBeFalse)
So(it.Type(), ShouldEqual, "all")
So(it.Type(), ShouldEqual, graph.All)
re_it, ok := it.Optimize()
So(ok, ShouldBeFalse)
So(re_it, ShouldPointTo, it)
@ -407,7 +407,7 @@ func TestOptimize(t *testing.T) {
oldIt := lto.Clone()
newIt, ok := lto.Optimize()
So(ok, ShouldBeTrue)
So(newIt.Type(), ShouldEqual, "leveldb")
So(newIt.Type(), ShouldEqual, Type())
Convey("Containing the right things", func() {
afterOp := extractTripleFromIterator(ts, newIt)

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()