rename to paths
This commit is contained in:
parent
cb2caad603
commit
287ea63e2d
2 changed files with 10 additions and 14 deletions
|
|
@ -26,16 +26,12 @@ type morphism struct {
|
||||||
Apply graph.MorphismFunc
|
Apply graph.MorphismFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
type iteratorMorphism interface {
|
|
||||||
Apply(graph.Iterator) graph.Iterator
|
|
||||||
}
|
|
||||||
|
|
||||||
type Path struct {
|
type Path struct {
|
||||||
stack []morphism
|
stack []morphism
|
||||||
qs graph.QuadStore
|
qs graph.QuadStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func V(qs graph.QuadStore, nodes ...string) *Path {
|
func StartPath(qs graph.QuadStore, nodes ...string) *Path {
|
||||||
return &Path{
|
return &Path{
|
||||||
stack: []morphism{
|
stack: []morphism{
|
||||||
isMorphism(qs, nodes...),
|
isMorphism(qs, nodes...),
|
||||||
|
|
@ -53,14 +49,14 @@ func PathFromIterator(qs graph.QuadStore, it graph.Iterator) *Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func M(qs graph.QuadStore) *Path {
|
func NewPath(qs graph.QuadStore) *Path {
|
||||||
return &Path{
|
return &Path{
|
||||||
qs: qs,
|
qs: qs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Path) Reverse() *Path {
|
func (p *Path) Reverse() *Path {
|
||||||
newPath := M(p.qs)
|
newPath := NewPath(p.qs)
|
||||||
for i := len(p.stack) - 1; i >= 0; i-- {
|
for i := len(p.stack) - 1; i >= 0; i-- {
|
||||||
newPath.stack = append(newPath.stack, p.stack[i].Reversal())
|
newPath.stack = append(newPath.stack, p.stack[i].Reversal())
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +212,7 @@ func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
|
||||||
if path, ok := v.(*Path); ok {
|
if path, ok := v.(*Path); ok {
|
||||||
return path
|
return path
|
||||||
} else if str, ok := v.(string); ok {
|
} else if str, ok := v.(string); ok {
|
||||||
return V(qs, str)
|
return StartPath(qs, str)
|
||||||
} else {
|
} else {
|
||||||
panic("Invalid type passed to buildViaPath.")
|
panic("Invalid type passed to buildViaPath.")
|
||||||
}
|
}
|
||||||
|
|
@ -229,5 +225,5 @@ func buildViaPath(qs graph.QuadStore, via ...interface{}) *Path {
|
||||||
panic("Non-string type passed to long Via path")
|
panic("Non-string type passed to long Via path")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return V(qs, strings...)
|
return StartPath(qs, strings...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,23 +72,23 @@ func testSet(qs graph.QuadStore) []test {
|
||||||
return []test{
|
return []test{
|
||||||
{
|
{
|
||||||
message: "use out",
|
message: "use out",
|
||||||
path: V(qs, "A").Out("follows"),
|
path: StartPath(qs, "A").Out("follows"),
|
||||||
expect: []string{"B"},
|
expect: []string{"B"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "use in",
|
message: "use in",
|
||||||
path: V(qs, "B").In("follows"),
|
path: StartPath(qs, "B").In("follows"),
|
||||||
expect: []string{"A", "C", "D"},
|
expect: []string{"A", "C", "D"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "use path Out",
|
message: "use path Out",
|
||||||
path: V(qs, "B").Out(V(qs, "predicates").Out("are")),
|
path: StartPath(qs, "B").Out(StartPath(qs, "predicates").Out("are")),
|
||||||
expect: []string{"F", "cool"},
|
expect: []string{"F", "cool"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "in",
|
message: "in",
|
||||||
path: V(qs, "D").Out("follows").And(
|
path: StartPath(qs, "D").Out("follows").And(
|
||||||
V(qs, "C").Out("follows")),
|
StartPath(qs, "C").Out("follows")),
|
||||||
expect: []string{"B"},
|
expect: []string{"B"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue