var renames, remove Func, etc

This commit is contained in:
Barak Michener 2015-02-10 19:07:43 -05:00
parent b9ca485321
commit 0e50027be8
2 changed files with 23 additions and 24 deletions

View file

@ -165,8 +165,8 @@ type Description struct {
Iterators []Description `json:",omitempty"` Iterators []Description `json:",omitempty"`
} }
// A curried function that can generates a new iterator based on some prior iterator. // ApplyMorphism is a curried function that can generates a new iterator based on some prior iterator.
type ApplyMorphismFunc func(QuadStore, Iterator) Iterator type ApplyMorphism func(QuadStore, Iterator) Iterator
type Nexter interface { type Nexter interface {
// Next advances the iterator to the next value, which will then be available through // Next advances the iterator to the next value, which will then be available through

View file

@ -23,7 +23,7 @@ import (
type morphism struct { type morphism struct {
Name string Name string
Reversal func() morphism Reversal func() morphism
Apply graph.ApplyMorphismFunc Apply graph.ApplyMorphism
} }
type Path struct { type Path struct {
@ -121,11 +121,10 @@ func (p *Path) BuildIterator() graph.Iterator {
} }
func (p *Path) BuildIteratorOn(qs graph.QuadStore) graph.Iterator { func (p *Path) BuildIteratorOn(qs graph.QuadStore) graph.Iterator {
f := p.MorphismFunc() return p.Morphism()(qs, qs.NodesAllIterator())
return f(qs, qs.NodesAllIterator())
} }
func (p *Path) MorphismFunc() graph.ApplyMorphismFunc { func (p *Path) Morphism() graph.ApplyMorphism {
return func(qs graph.QuadStore, it graph.Iterator) graph.Iterator { return func(qs graph.QuadStore, it graph.Iterator) graph.Iterator {
i := it.Clone() i := it.Clone()
for _, m := range p.stack { for _, m := range p.stack {
@ -205,12 +204,12 @@ func iteratorMorphism(it graph.Iterator) morphism {
} }
} }
func andMorphism(path *Path) morphism { func andMorphism(p *Path) morphism {
return morphism{ return morphism{
"and", "and",
func() morphism { return andMorphism(path) }, func() morphism { return andMorphism(p) },
func(qs graph.QuadStore, it graph.Iterator) graph.Iterator { func(qs graph.QuadStore, it graph.Iterator) graph.Iterator {
subIt := path.BuildIteratorOn(qs) subIt := p.BuildIteratorOn(qs)
and := iterator.NewAnd() and := iterator.NewAnd()
and.AddSubIterator(it) and.AddSubIterator(it)
and.AddSubIterator(subIt) and.AddSubIterator(subIt)
@ -219,12 +218,12 @@ func andMorphism(path *Path) morphism {
} }
} }
func orMorphism(path *Path) morphism { func orMorphism(p *Path) morphism {
return morphism{ return morphism{
"or", "or",
func() morphism { return orMorphism(path) }, func() morphism { return orMorphism(p) },
func(qs graph.QuadStore, it graph.Iterator) graph.Iterator { func(qs graph.QuadStore, it graph.Iterator) graph.Iterator {
subIt := path.BuildIteratorOn(qs) subIt := p.BuildIteratorOn(qs)
and := iterator.NewOr() and := iterator.NewOr()
and.AddSubIterator(it) and.AddSubIterator(it)
and.AddSubIterator(subIt) and.AddSubIterator(subIt)
@ -233,23 +232,22 @@ func orMorphism(path *Path) morphism {
} }
} }
func followMorphism(path *Path) morphism { func followMorphism(p *Path) morphism {
return morphism{ return morphism{
"follow", "follow",
func() morphism { return followMorphism(path.Reverse()) }, func() morphism { return followMorphism(p.Reverse()) },
func(qs graph.QuadStore, base graph.Iterator) graph.Iterator { func(qs graph.QuadStore, base graph.Iterator) graph.Iterator {
p := path.MorphismFunc() return p.Morphism()(qs, base)
return p(qs, base)
}, },
} }
} }
func exceptMorphism(path *Path) morphism { func exceptMorphism(p *Path) morphism {
return morphism{ return morphism{
"except", "except",
func() morphism { return exceptMorphism(path) }, func() morphism { return exceptMorphism(p) },
func(qs graph.QuadStore, base graph.Iterator) graph.Iterator { func(qs graph.QuadStore, base graph.Iterator) graph.Iterator {
subIt := path.BuildIteratorOn(qs) subIt := p.BuildIteratorOn(qs)
notIt := iterator.NewNot(subIt, qs.NodesAllIterator()) notIt := iterator.NewNot(subIt, qs.NodesAllIterator())
and := iterator.NewAnd() and := iterator.NewAnd()
and.AddSubIterator(base) and.AddSubIterator(base)
@ -276,11 +274,12 @@ func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
return PathFromIterator(qs, qs.NodesAllIterator()) return PathFromIterator(qs, qs.NodesAllIterator())
} else if len(via) == 1 { } else if len(via) == 1 {
v := via[0] v := via[0]
if path, ok := v.(*Path); ok { switch v := v.(type) {
return path case *Path:
} else if str, ok := v.(string); ok { return v
return StartPath(qs, str) case string:
} else { return StartPath(qs, v)
default:
panic("Invalid type passed to buildViaPath.") panic("Invalid type passed to buildViaPath.")
} }
} }