Clean up Linkage definition
A linkage is a direction/value pair, and that's all. A set of these can have helper functions and the like. Cleans up some assumptions of functionality that isn't useful (yet).
This commit is contained in:
parent
3a7da9f2a0
commit
d639aa3205
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
|
||||
// quad direction.
|
||||
type Linkage struct {
|
||||
Dir quad.Direction
|
||||
Values []Value
|
||||
Dir quad.Direction
|
||||
Value Value
|
||||
}
|
||||
|
||||
// TODO(barakmich): Helper functions as needed, eg, ValuesForDirection(quad.Direction) []Value
|
||||
|
||||
// Add a tag to the iterator.
|
||||
func (t *Tagger) Add(tag string) {
|
||||
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 {
|
||||
constraint := bson.M{}
|
||||
for _, set := range it.lset {
|
||||
var s []string
|
||||
for _, v := range set.Values {
|
||||
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]
|
||||
}
|
||||
// TODO(barakmich): Currently this only works for an individual linkage in any direction.
|
||||
for _, link := range it.lset {
|
||||
constraint[link.Dir.String()] = link.Value
|
||||
}
|
||||
return constraint
|
||||
}
|
||||
|
|
@ -201,16 +195,9 @@ func (it *LinksTo) Contains(val graph.Value) bool {
|
|||
graph.ContainsLogIn(it, val)
|
||||
it.runstats.Contains += 1
|
||||
|
||||
for _, set := range it.lset {
|
||||
dval := it.qs.QuadDirection(val, set.Dir)
|
||||
good := false
|
||||
for _, val := range set.Values {
|
||||
if val == dval {
|
||||
good = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !good {
|
||||
for _, link := range it.lset {
|
||||
dval := it.qs.QuadDirection(val, link.Dir)
|
||||
if dval != link.Value {
|
||||
return graph.ContainsLogOut(it, val, false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool
|
|||
lset := []graph.Linkage{
|
||||
{
|
||||
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