Remove redundant loggin functions

This commit is contained in:
kortschak 2014-07-01 10:52:31 +09:30
parent 2f2f580858
commit a31a5a170c
7 changed files with 38 additions and 74 deletions

View file

@ -67,9 +67,9 @@ func (it *Int64) DebugString(indent int) string {
// Next() on an Int64 all iterator is a simple incrementing counter. // Next() on an Int64 all iterator is a simple incrementing counter.
// Return the next integer, and mark it as the result. // Return the next integer, and mark it as the result.
func (it *Int64) Next() (graph.TSVal, bool) { func (it *Int64) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
if it.at == -1 { if it.at == -1 {
return NextLogOut(it, nil, false) return graph.NextLogOut(it, nil, false)
} }
val := it.at val := it.at
it.at = it.at + 1 it.at = it.at + 1
@ -77,7 +77,7 @@ func (it *Int64) Next() (graph.TSVal, bool) {
it.at = -1 it.at = -1
} }
it.Last = val it.Last = val
return NextLogOut(it, val, true) return graph.NextLogOut(it, val, true)
} }
// The number of elements in an Int64 is the size of the range. // The number of elements in an Int64 is the size of the range.
@ -90,13 +90,13 @@ func (it *Int64) Size() (int64, bool) {
// Check() for an Int64 is merely seeing if the passed value is // Check() for an Int64 is merely seeing if the passed value is
// withing the range, assuming the value is an int64. // withing the range, assuming the value is an int64.
func (it *Int64) Check(tsv graph.TSVal) bool { func (it *Int64) Check(tsv graph.TSVal) bool {
CheckLogIn(it, tsv) graph.CheckLogIn(it, tsv)
v := tsv.(int64) v := tsv.(int64)
if it.min <= v && v <= it.max { if it.min <= v && v <= it.max {
it.Last = v it.Last = v
return CheckLogOut(it, v, true) return graph.CheckLogOut(it, v, true)
} }
return CheckLogOut(it, v, false) return graph.CheckLogOut(it, v, false)
} }
// The type of this iterator is an "all". This is important, as it puts it in // The type of this iterator is an "all". This is important, as it puts it in

View file

@ -139,17 +139,17 @@ func (it *And) AddSubIterator(sub graph.Iterator) {
// candidate, and check this value against the subiterators. A productive choice // candidate, and check this value against the subiterators. A productive choice
// of primary iterator is therefore very important. // of primary iterator is therefore very important.
func (it *And) Next() (graph.TSVal, bool) { func (it *And) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
var curr graph.TSVal var curr graph.TSVal
var exists bool var exists bool
for { for {
curr, exists = it.primaryIt.Next() curr, exists = it.primaryIt.Next()
if !exists { if !exists {
return NextLogOut(it, nil, false) return graph.NextLogOut(it, nil, false)
} }
if it.checkSubIts(curr) { if it.checkSubIts(curr) {
it.Last = curr it.Last = curr
return NextLogOut(it, curr, true) return graph.NextLogOut(it, curr, true)
} }
} }
panic("Somehow broke out of Next() loop in And") panic("Somehow broke out of Next() loop in And")
@ -178,25 +178,25 @@ func (it *And) checkCheckList(val graph.TSVal) bool {
if ok { if ok {
it.Last = val it.Last = val
} }
return CheckLogOut(it, val, ok) return graph.CheckLogOut(it, val, ok)
} }
// Check a value against the entire iterator, in order. // Check a value against the entire iterator, in order.
func (it *And) Check(val graph.TSVal) bool { func (it *And) Check(val graph.TSVal) bool {
CheckLogIn(it, val) graph.CheckLogIn(it, val)
if it.checkList != nil { if it.checkList != nil {
return it.checkCheckList(val) return it.checkCheckList(val)
} }
mainGood := it.primaryIt.Check(val) mainGood := it.primaryIt.Check(val)
if !mainGood { if !mainGood {
return CheckLogOut(it, val, false) return graph.CheckLogOut(it, val, false)
} }
othersGood := it.checkSubIts(val) othersGood := it.checkSubIts(val)
if !othersGood { if !othersGood {
return CheckLogOut(it, val, false) return graph.CheckLogOut(it, val, false)
} }
it.Last = val it.Last = val
return CheckLogOut(it, val, true) return graph.CheckLogOut(it, val, true)
} }
// Returns the approximate size of the And iterator. Because we're dealing // Returns the approximate size of the And iterator. Because we're dealing

View file

@ -108,26 +108,26 @@ func (it *Fixed) Check(v graph.TSVal) bool {
// Could be optimized by keeping it sorted or using a better datastructure. // Could be optimized by keeping it sorted or using a better datastructure.
// However, for fixed iterators, which are by definition kind of tiny, this // However, for fixed iterators, which are by definition kind of tiny, this
// isn't a big issue. // isn't a big issue.
CheckLogIn(it, v) graph.CheckLogIn(it, v)
for _, x := range it.values { for _, x := range it.values {
if it.cmp(x, v) { if it.cmp(x, v) {
it.Last = x it.Last = x
return CheckLogOut(it, v, true) return graph.CheckLogOut(it, v, true)
} }
} }
return CheckLogOut(it, v, false) return graph.CheckLogOut(it, v, false)
} }
// Return the next stored value from the iterator. // Return the next stored value from the iterator.
func (it *Fixed) Next() (graph.TSVal, bool) { func (it *Fixed) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
if it.lastIndex == len(it.values) { if it.lastIndex == len(it.values) {
return NextLogOut(it, nil, false) return graph.NextLogOut(it, nil, false)
} }
out := it.values[it.lastIndex] out := it.values[it.lastIndex]
it.Last = out it.Last = out
it.lastIndex++ it.lastIndex++
return NextLogOut(it, out, true) return graph.NextLogOut(it, out, true)
} }
// Optimize() for a Fixed iterator is simple. Returns a Null iterator if it's empty // Optimize() for a Fixed iterator is simple. Returns a Null iterator if it's empty

View file

@ -124,7 +124,7 @@ func (it *HasA) DebugString(indent int) string {
// iterator of "triples that have `val` in our direction", given to us by the triple store, // 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. // and then Next() values out of that iterator and Check() them against our subiterator.
func (it *HasA) Check(val graph.TSVal) bool { func (it *HasA) Check(val graph.TSVal) bool {
CheckLogIn(it, val) graph.CheckLogIn(it, val)
if glog.V(4) { if glog.V(4) {
glog.V(4).Infoln("Id is", it.ts.GetNameFor(val)) glog.V(4).Infoln("Id is", it.ts.GetNameFor(val))
} }
@ -133,7 +133,7 @@ func (it *HasA) Check(val graph.TSVal) bool {
it.resultIt.Close() it.resultIt.Close()
} }
it.resultIt = it.ts.GetTripleIterator(it.dir, val) it.resultIt = it.ts.GetTripleIterator(it.dir, val)
return CheckLogOut(it, val, it.GetCheckResult()) return graph.CheckLogOut(it, val, it.GetCheckResult())
} }
// GetCheckResult() is shared code between Check() and GetNextResult() -- calls next on the // GetCheckResult() is shared code between Check() and GetNextResult() -- calls next on the
@ -174,7 +174,7 @@ func (it *HasA) NextResult() bool {
// subiterator we can get a value from, and we can take that resultant triple, // subiterator we can get a value from, and we can take that resultant triple,
// pull our direction out of it, and return that. // pull our direction out of it, and return that.
func (it *HasA) Next() (graph.TSVal, bool) { func (it *HasA) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
if it.resultIt != nil { if it.resultIt != nil {
it.resultIt.Close() it.resultIt.Close()
} }
@ -182,12 +182,12 @@ func (it *HasA) Next() (graph.TSVal, bool) {
tID, ok := it.primaryIt.Next() tID, ok := it.primaryIt.Next()
if !ok { if !ok {
return NextLogOut(it, 0, false) return graph.NextLogOut(it, 0, false)
} }
name := it.ts.GetTriple(tID).Get(it.dir) name := it.ts.GetTriple(tID).Get(it.dir)
val := it.ts.GetIdFor(name) val := it.ts.GetIdFor(name)
it.Last = val it.Last = val
return NextLogOut(it, val, true) return graph.NextLogOut(it, val, true)
} }
// GetStats() returns the statistics on the HasA iterator. This is curious. Next // GetStats() returns the statistics on the HasA iterator. This is curious. Next

View file

@ -185,39 +185,3 @@ func (it *Null) DebugString(indent int) string {
func (it *Null) GetStats() *graph.IteratorStats { func (it *Null) GetStats() *graph.IteratorStats {
return &graph.IteratorStats{} return &graph.IteratorStats{}
} }
// Utility logging functions for when an iterator gets called Next upon, or Check upon, as
// well as what they return. Highly useful for tracing the execution path of a query.
func CheckLogIn(it graph.Iterator, val graph.TSVal) {
if glog.V(4) {
glog.V(4).Infof("%s %d CHECK %d", strings.ToUpper(it.Type()), it.GetUid(), val)
}
}
func CheckLogOut(it graph.Iterator, val graph.TSVal, good bool) bool {
if glog.V(4) {
if good {
glog.V(4).Infof("%s %d CHECK %d GOOD", strings.ToUpper(it.Type()), it.GetUid(), val)
} else {
glog.V(4).Infof("%s %d CHECK %d BAD", strings.ToUpper(it.Type()), it.GetUid(), val)
}
}
return good
}
func NextLogIn(it graph.Iterator) {
if glog.V(4) {
glog.V(4).Infof("%s %d NEXT", strings.ToUpper(it.Type()), it.GetUid())
}
}
func NextLogOut(it graph.Iterator, val graph.TSVal, ok bool) (graph.TSVal, bool) {
if glog.V(4) {
if ok {
glog.V(4).Infof("%s %d NEXT IS %d", strings.ToUpper(it.Type()), it.GetUid(), val)
} else {
glog.V(4).Infof("%s %d NEXT DONE", strings.ToUpper(it.Type()), it.GetUid())
}
}
return val, ok
}

View file

@ -99,13 +99,13 @@ func (it *LinksTo) DebugString(indent int) string {
// If it checks in the right direction for the subiterator, it is a valid link // If it checks in the right direction for the subiterator, it is a valid link
// for the LinksTo. // for the LinksTo.
func (it *LinksTo) Check(val graph.TSVal) bool { func (it *LinksTo) Check(val graph.TSVal) bool {
CheckLogIn(it, val) graph.CheckLogIn(it, val)
node := it.ts.GetTripleDirection(val, it.dir) node := it.ts.GetTripleDirection(val, it.dir)
if it.primaryIt.Check(node) { if it.primaryIt.Check(node) {
it.Last = val it.Last = val
return CheckLogOut(it, val, true) return graph.CheckLogOut(it, val, true)
} }
return CheckLogOut(it, val, false) return graph.CheckLogOut(it, val, false)
} }
// Return a list containing only our subiterator. // Return a list containing only our subiterator.
@ -136,14 +136,14 @@ func (it *LinksTo) Optimize() (graph.Iterator, bool) {
// Next()ing a LinksTo operates as described above. // Next()ing a LinksTo operates as described above.
func (it *LinksTo) Next() (graph.TSVal, bool) { func (it *LinksTo) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
val, ok := it.nextIt.Next() val, ok := it.nextIt.Next()
if !ok { if !ok {
// Subiterator is empty, get another one // Subiterator is empty, get another one
candidate, ok := it.primaryIt.Next() candidate, ok := it.primaryIt.Next()
if !ok { if !ok {
// We're out of nodes in our subiterator, so we're done as well. // We're out of nodes in our subiterator, so we're done as well.
return NextLogOut(it, 0, false) return graph.NextLogOut(it, 0, false)
} }
it.nextIt.Close() it.nextIt.Close()
it.nextIt = it.ts.GetTripleIterator(it.dir, candidate) it.nextIt = it.ts.GetTripleIterator(it.dir, candidate)
@ -151,7 +151,7 @@ func (it *LinksTo) Next() (graph.TSVal, bool) {
return it.Next() return it.Next()
} }
it.Last = val it.Last = val
return NextLogOut(it, val, ok) return graph.NextLogOut(it, val, ok)
} }
// Close our subiterators. // Close our subiterators.

View file

@ -129,7 +129,7 @@ func (it *Or) AddSubIterator(sub graph.Iterator) {
// union of its subiterators, it must produce from all subiterators -- unless // union of its subiterators, it must produce from all subiterators -- unless
// it's shortcircuiting, in which case, it's the first one that returns anything. // it's shortcircuiting, in which case, it's the first one that returns anything.
func (it *Or) Next() (graph.TSVal, bool) { func (it *Or) Next() (graph.TSVal, bool) {
NextLogIn(it) graph.NextLogIn(it)
var curr graph.TSVal var curr graph.TSVal
var exists bool var exists bool
firstTime := false firstTime := false
@ -142,15 +142,15 @@ func (it *Or) Next() (graph.TSVal, bool) {
curr, exists = curIt.Next() curr, exists = curIt.Next()
if !exists { if !exists {
if it.isShortCircuiting && !firstTime { if it.isShortCircuiting && !firstTime {
return NextLogOut(it, nil, false) return graph.NextLogOut(it, nil, false)
} }
it.currentIterator++ it.currentIterator++
if it.currentIterator == it.itCount { if it.currentIterator == it.itCount {
return NextLogOut(it, nil, false) return graph.NextLogOut(it, nil, false)
} }
} else { } else {
it.Last = curr it.Last = curr
return NextLogOut(it, curr, true) return graph.NextLogOut(it, curr, true)
} }
} }
panic("Somehow broke out of Next() loop in Or") panic("Somehow broke out of Next() loop in Or")
@ -171,13 +171,13 @@ func (it *Or) checkSubIts(val graph.TSVal) bool {
// Check a value against the entire graph.iterator, in order. // Check a value against the entire graph.iterator, in order.
func (it *Or) Check(val graph.TSVal) bool { func (it *Or) Check(val graph.TSVal) bool {
CheckLogIn(it, val) graph.CheckLogIn(it, val)
anyGood := it.checkSubIts(val) anyGood := it.checkSubIts(val)
if !anyGood { if !anyGood {
return CheckLogOut(it, val, false) return graph.CheckLogOut(it, val, false)
} }
it.Last = val it.Last = val
return CheckLogOut(it, val, true) return graph.CheckLogOut(it, val, true)
} }
// Returns the approximate size of the Or graph.iterator. Because we're dealing // Returns the approximate size of the Or graph.iterator. Because we're dealing