Rename Check-ish -> Contains-ish
Contains[*] indicates what the check is for. [*] I considered Has/Have, but settled on Contains to avoid confusion with the HasA iterator.
This commit is contained in:
parent
a81005ba21
commit
1606e98d9f
20 changed files with 142 additions and 143 deletions
|
|
@ -23,10 +23,10 @@ package iterator
|
|||
// path. That's okay -- in reality, it can be viewed as returning the value for
|
||||
// a new triple, but to make logic much simpler, here we have the HasA.
|
||||
//
|
||||
// Likewise, it's important to think about Check()ing a HasA. When given a
|
||||
// Likewise, it's important to think about Contains()ing a HasA. When given a
|
||||
// value to check, it means "Check all predicates that have this value for your
|
||||
// direction against the subiterator." This would imply that there's more than
|
||||
// one possibility for the same Check()ed value. While we could return the
|
||||
// one possibility for the same Contains()ed value. While we could return the
|
||||
// number of options, it's simpler to return one, and then call NextResult()
|
||||
// enough times to enumerate the options. (In fact, one could argue that the
|
||||
// raison d'etre for NextResult() is this iterator).
|
||||
|
|
@ -45,7 +45,7 @@ import (
|
|||
|
||||
// A HasA consists of a reference back to the graph.TripleStore that it references,
|
||||
// a primary subiterator, a direction in which the triples for that subiterator point,
|
||||
// and a temporary holder for the iterator generated on Check().
|
||||
// and a temporary holder for the iterator generated on Contains().
|
||||
type HasA struct {
|
||||
uid uint64
|
||||
tags graph.Tagger
|
||||
|
|
@ -140,9 +140,9 @@ func (it *HasA) DebugString(indent int) string {
|
|||
|
||||
// Check a value against our internal iterator. In order to do this, we must first open a new
|
||||
// iterator of "triples that have `val` in our direction", given to us by the triple store,
|
||||
// and then Next() values out of that iterator and Check() them against our subiterator.
|
||||
func (it *HasA) Check(val graph.Value) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
// and then Next() values out of that iterator and Contains() them against our subiterator.
|
||||
func (it *HasA) Contains(val graph.Value) bool {
|
||||
graph.ContainsLogIn(it, val)
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Id is", it.ts.NameOf(val))
|
||||
}
|
||||
|
|
@ -151,13 +151,13 @@ func (it *HasA) Check(val graph.Value) bool {
|
|||
it.resultIt.Close()
|
||||
}
|
||||
it.resultIt = it.ts.TripleIterator(it.dir, val)
|
||||
return graph.CheckLogOut(it, val, it.GetCheckResult())
|
||||
return graph.ContainsLogOut(it, val, it.NextContains())
|
||||
}
|
||||
|
||||
// GetCheckResult() is shared code between Check() and GetNextResult() -- calls next on the
|
||||
// NextContains() is shared code between Contains() and GetNextResult() -- calls next on the
|
||||
// result iterator (a triple iterator based on the last checked value) and returns true if
|
||||
// another match is made.
|
||||
func (it *HasA) GetCheckResult() bool {
|
||||
func (it *HasA) NextContains() bool {
|
||||
for {
|
||||
linkVal, ok := graph.Next(it.resultIt)
|
||||
if !ok {
|
||||
|
|
@ -166,7 +166,7 @@ func (it *HasA) GetCheckResult() bool {
|
|||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Quad is", it.ts.Quad(linkVal))
|
||||
}
|
||||
if it.primaryIt.Check(linkVal) {
|
||||
if it.primaryIt.Contains(linkVal) {
|
||||
it.result = it.ts.TripleDirection(linkVal, it.dir)
|
||||
return true
|
||||
}
|
||||
|
|
@ -178,17 +178,17 @@ func (it *HasA) GetCheckResult() bool {
|
|||
func (it *HasA) NextResult() bool {
|
||||
// Order here is important. If the subiterator has a NextResult, then we
|
||||
// need do nothing -- there is a next result, and we shouldn't move forward.
|
||||
// However, we then need to get the next result from our last Check().
|
||||
// However, we then need to get the next result from our last Contains().
|
||||
//
|
||||
// The upshot is, the end of NextResult() bubbles up from the bottom of the
|
||||
// iterator tree up, and we need to respect that.
|
||||
if it.primaryIt.NextResult() {
|
||||
return true
|
||||
}
|
||||
return it.GetCheckResult()
|
||||
return it.NextContains()
|
||||
}
|
||||
|
||||
// Get the next result from this iterator. This is simpler than Check. We have a
|
||||
// Get the next result from this iterator. This is simpler than Contains. We have a
|
||||
// subiterator we can get a value from, and we can take that resultant triple,
|
||||
// pull our direction out of it, and return that.
|
||||
func (it *HasA) Next() (graph.Value, bool) {
|
||||
|
|
@ -214,7 +214,7 @@ func (it *HasA) Result() graph.Value {
|
|||
|
||||
// GetStats() returns the statistics on the HasA iterator. This is curious. Next
|
||||
// cost is easy, it's an extra call or so on top of the subiterator Next cost.
|
||||
// CheckCost involves going to the graph.TripleStore, iterating out values, and hoping
|
||||
// ContainsCost involves going to the graph.TripleStore, iterating out values, and hoping
|
||||
// one sticks -- potentially expensive, depending on fanout. Size, however, is
|
||||
// potentially smaller. we know at worst it's the size of the subiterator, but
|
||||
// if there are many repeated values, it could be much smaller in totality.
|
||||
|
|
@ -227,9 +227,9 @@ func (it *HasA) Stats() graph.IteratorStats {
|
|||
nextConstant := int64(2)
|
||||
tripleConstant := int64(1)
|
||||
return graph.IteratorStats{
|
||||
NextCost: tripleConstant + subitStats.NextCost,
|
||||
CheckCost: (fanoutFactor * nextConstant) * subitStats.CheckCost,
|
||||
Size: faninFactor * subitStats.Size,
|
||||
NextCost: tripleConstant + subitStats.NextCost,
|
||||
ContainsCost: (fanoutFactor * nextConstant) * subitStats.ContainsCost,
|
||||
Size: faninFactor * subitStats.Size,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue