Merge pull request #247 from barakmich/linkage
Clean up Linkage definition
This commit is contained in:
commit
c2e410dd2c
3 changed files with 11 additions and 22 deletions
|
|
@ -38,10 +38,12 @@ type Tagger struct {
|
||||||
// Linkage is a union type representing a set of values established for a given
|
// Linkage is a union type representing a set of values established for a given
|
||||||
// quad direction.
|
// quad direction.
|
||||||
type Linkage struct {
|
type Linkage struct {
|
||||||
Dir quad.Direction
|
Dir quad.Direction
|
||||||
Values []Value
|
Value Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(barakmich): Helper functions as needed, eg, ValuesForDirection(quad.Direction) []Value
|
||||||
|
|
||||||
// Add a tag to the iterator.
|
// Add a tag to the iterator.
|
||||||
func (t *Tagger) Add(tag string) {
|
func (t *Tagger) Add(tag string) {
|
||||||
t.tags = append(t.tags, tag)
|
t.tags = append(t.tags, tag)
|
||||||
|
|
|
||||||
|
|
@ -66,15 +66,9 @@ func NewLinksTo(qs *QuadStore, it graph.Iterator, collection string, d quad.Dire
|
||||||
|
|
||||||
func (it *LinksTo) buildConstraint() bson.M {
|
func (it *LinksTo) buildConstraint() bson.M {
|
||||||
constraint := bson.M{}
|
constraint := bson.M{}
|
||||||
for _, set := range it.lset {
|
// TODO(barakmich): Currently this only works for an individual linkage in any direction.
|
||||||
var s []string
|
for _, link := range it.lset {
|
||||||
for _, v := range set.Values {
|
constraint[link.Dir.String()] = link.Value
|
||||||
s = append(s, it.qs.NameOf(v))
|
|
||||||
}
|
|
||||||
constraint[set.Dir.String()] = bson.M{"$in": s}
|
|
||||||
if len(s) == 1 {
|
|
||||||
constraint[set.Dir.String()] = s[0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return constraint
|
return constraint
|
||||||
}
|
}
|
||||||
|
|
@ -201,16 +195,9 @@ func (it *LinksTo) Contains(val graph.Value) bool {
|
||||||
graph.ContainsLogIn(it, val)
|
graph.ContainsLogIn(it, val)
|
||||||
it.runstats.Contains += 1
|
it.runstats.Contains += 1
|
||||||
|
|
||||||
for _, set := range it.lset {
|
for _, link := range it.lset {
|
||||||
dval := it.qs.QuadDirection(val, set.Dir)
|
dval := it.qs.QuadDirection(val, link.Dir)
|
||||||
good := false
|
if dval != link.Value {
|
||||||
for _, val := range set.Values {
|
|
||||||
if val == dval {
|
|
||||||
good = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !good {
|
|
||||||
return graph.ContainsLogOut(it, val, false)
|
return graph.ContainsLogOut(it, val, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool
|
||||||
lset := []graph.Linkage{
|
lset := []graph.Linkage{
|
||||||
{
|
{
|
||||||
Dir: mongoIt.dir,
|
Dir: mongoIt.dir,
|
||||||
Values: []graph.Value{qs.ValueOf(mongoIt.name)},
|
Value: qs.ValueOf(mongoIt.name),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue