Canonicalise iterator receiver names

This apparently meaningless churn improves godoc readability.
This commit is contained in:
kortschak 2014-06-28 21:36:50 +09:30
parent dc65ebce9e
commit 60d5c60817
10 changed files with 432 additions and 435 deletions

View file

@ -41,80 +41,80 @@ func NewAndIterator() *AndIterator {
}
// Reset all internal iterators
func (and *AndIterator) Reset() {
and.primaryIt.Reset()
for _, it := range and.internalIterators {
it.Reset()
func (it *AndIterator) Reset() {
it.primaryIt.Reset()
for _, sub := range it.internalIterators {
sub.Reset()
}
and.checkList = nil
it.checkList = nil
}
func (and *AndIterator) Clone() Iterator {
newAnd := NewAndIterator()
newAnd.AddSubIterator(and.primaryIt.Clone())
newAnd.CopyTagsFrom(and)
for _, it := range and.internalIterators {
newAnd.AddSubIterator(it.Clone())
func (it *AndIterator) Clone() Iterator {
and := NewAndIterator()
and.AddSubIterator(it.primaryIt.Clone())
and.CopyTagsFrom(it)
for _, sub := range it.internalIterators {
and.AddSubIterator(sub.Clone())
}
if and.checkList != nil {
newAnd.optimizeCheck()
if it.checkList != nil {
and.optimizeCheck()
}
return newAnd
return and
}
// Returns a list.List of the subiterators, in order (primary iterator first).
func (and *AndIterator) GetSubIterators() *list.List {
func (it *AndIterator) GetSubIterators() *list.List {
l := list.New()
l.PushBack(and.primaryIt)
for _, it := range and.internalIterators {
l.PushBack(it)
l.PushBack(it.primaryIt)
for _, sub := range it.internalIterators {
l.PushBack(sub)
}
return l
}
// Overrides BaseIterator TagResults, as it needs to add it's own results and
// recurse down it's subiterators.
func (and *AndIterator) TagResults(out *map[string]TSVal) {
and.BaseIterator.TagResults(out)
if and.primaryIt != nil {
and.primaryIt.TagResults(out)
func (it *AndIterator) TagResults(out *map[string]TSVal) {
it.BaseIterator.TagResults(out)
if it.primaryIt != nil {
it.primaryIt.TagResults(out)
}
for _, it := range and.internalIterators {
it.TagResults(out)
for _, sub := range it.internalIterators {
sub.TagResults(out)
}
}
// DEPRECATED Returns the ResultTree for this iterator, recurses to it's subiterators.
func (and *AndIterator) GetResultTree() *ResultTree {
tree := NewResultTree(and.LastResult())
tree.AddSubtree(and.primaryIt.GetResultTree())
for _, it := range and.internalIterators {
tree.AddSubtree(it.GetResultTree())
func (it *AndIterator) GetResultTree() *ResultTree {
tree := NewResultTree(it.LastResult())
tree.AddSubtree(it.primaryIt.GetResultTree())
for _, sub := range it.internalIterators {
tree.AddSubtree(sub.GetResultTree())
}
return tree
}
// Prints information about this iterator.
func (and *AndIterator) DebugString(indent int) string {
func (it *AndIterator) DebugString(indent int) string {
var total string
for i, it := range and.internalIterators {
for i, sub := range it.internalIterators {
total += strings.Repeat(" ", indent+2)
total += fmt.Sprintf("%d:\n%s\n", i, it.DebugString(indent+4))
total += fmt.Sprintf("%d:\n%s\n", i, sub.DebugString(indent+4))
}
var tags string
for _, k := range and.Tags() {
for _, k := range it.Tags() {
tags += fmt.Sprintf("%s;", k)
}
spaces := strings.Repeat(" ", indent+2)
return fmt.Sprintf("%s(%s %d\n%stags:%s\n%sprimary_it:\n%s\n%sother_its:\n%s)",
strings.Repeat(" ", indent),
and.Type(),
and.GetUid(),
it.Type(),
it.GetUid(),
spaces,
tags,
spaces,
and.primaryIt.DebugString(indent+4),
it.primaryIt.DebugString(indent+4),
spaces,
total)
}
@ -125,43 +125,42 @@ func (and *AndIterator) DebugString(indent int) string {
// important. Calling Optimize() is the way to change the order based on
// subiterator statistics. Without Optimize(), the order added is the order
// used.
func (and *AndIterator) AddSubIterator(sub Iterator) {
if and.itCount > 0 {
and.internalIterators = append(and.internalIterators, sub)
and.itCount++
func (it *AndIterator) AddSubIterator(sub Iterator) {
if it.itCount > 0 {
it.internalIterators = append(it.internalIterators, sub)
it.itCount++
return
}
and.primaryIt = sub
and.itCount++
it.primaryIt = sub
it.itCount++
}
// Returns the Next value from the And iterator. Because the And is the
// intersection of its subiterators, it must choose one subiterator to produce a
// candidate, and check this value against the subiterators. A productive choice
// of primary iterator is therefore very important.
func (and *AndIterator) Next() (TSVal, bool) {
NextLogIn(and)
func (it *AndIterator) Next() (TSVal, bool) {
NextLogIn(it)
var curr TSVal
var exists bool
for {
curr, exists = and.primaryIt.Next()
curr, exists = it.primaryIt.Next()
if !exists {
return NextLogOut(and, nil, false)
return NextLogOut(it, nil, false)
}
if and.checkSubIts(curr) {
and.Last = curr
return NextLogOut(and, curr, true)
if it.checkSubIts(curr) {
it.Last = curr
return NextLogOut(it, curr, true)
}
}
panic("Somehow broke out of Next() loop in AndIterator")
}
// Checks a value against the non-primary iterators, in order.
func (and *AndIterator) checkSubIts(val TSVal) bool {
func (it *AndIterator) checkSubIts(val TSVal) bool {
var subIsGood = true
for _, it := range and.internalIterators {
subIsGood = it.Check(val)
for _, sub := range it.internalIterators {
subIsGood = sub.Check(val)
if !subIsGood {
break
}
@ -169,43 +168,43 @@ func (and *AndIterator) checkSubIts(val TSVal) bool {
return subIsGood
}
func (and *AndIterator) checkCheckList(val TSVal) bool {
func (it *AndIterator) checkCheckList(val TSVal) bool {
var isGood = true
for e := and.checkList.Front(); e != nil; e = e.Next() {
for e := it.checkList.Front(); e != nil; e = e.Next() {
isGood = e.Value.(Iterator).Check(val)
if !isGood {
break
}
}
return CheckLogOut(and, val, isGood)
return CheckLogOut(it, val, isGood)
}
// Check a value against the entire iterator, in order.
func (and *AndIterator) Check(val TSVal) bool {
CheckLogIn(and, val)
if and.checkList != nil {
return and.checkCheckList(val)
func (it *AndIterator) Check(val TSVal) bool {
CheckLogIn(it, val)
if it.checkList != nil {
return it.checkCheckList(val)
}
mainGood := and.primaryIt.Check(val)
mainGood := it.primaryIt.Check(val)
if !mainGood {
return CheckLogOut(and, val, false)
return CheckLogOut(it, val, false)
}
othersGood := and.checkSubIts(val)
othersGood := it.checkSubIts(val)
if !othersGood {
return CheckLogOut(and, val, false)
return CheckLogOut(it, val, false)
}
and.Last = val
return CheckLogOut(and, val, true)
it.Last = val
return CheckLogOut(it, val, true)
}
// Returns the approximate size of the And iterator. Because we're dealing
// with an intersection, we know that the largest we can be is the size of the
// smallest iterator. This is the heuristic we shall follow. Better heuristics
// welcome.
func (and *AndIterator) Size() (int64, bool) {
val, b := and.primaryIt.Size()
for _, it := range and.internalIterators {
newval, newb := it.Size()
func (it *AndIterator) Size() (int64, bool) {
val, b := it.primaryIt.Size()
for _, sub := range it.internalIterators {
newval, newb := sub.Size()
if val > newval {
val = newval
}
@ -217,12 +216,12 @@ func (and *AndIterator) Size() (int64, bool) {
// An And has no NextResult of its own -- that is, there are no other values
// which satisfy our previous result that are not the result itself. Our
// subiterators might, however, so just pass the call recursively.
func (and *AndIterator) NextResult() bool {
if and.primaryIt.NextResult() {
func (it *AndIterator) NextResult() bool {
if it.primaryIt.NextResult() {
return true
}
for _, it := range and.internalIterators {
if it.NextResult() {
for _, sub := range it.internalIterators {
if sub.NextResult() {
return true
}
}
@ -230,19 +229,18 @@ func (and *AndIterator) NextResult() bool {
}
// Perform and-specific cleanup, of which there currently is none.
func (and *AndIterator) cleanUp() {
}
func (it *AndIterator) cleanUp() {}
// Close this iterator, and, by extension, close the subiterators.
// Close should be idempotent, and it follows that if it's subiterators
// follow this contract, the And follows the contract.
func (and *AndIterator) Close() {
and.cleanUp()
and.primaryIt.Close()
for _, it := range and.internalIterators {
it.Close()
func (it *AndIterator) Close() {
it.cleanUp()
it.primaryIt.Close()
for _, sub := range it.internalIterators {
sub.Close()
}
}
// Register this as an "and" iterator.
func (and *AndIterator) Type() string { return "and" }
func (it *AndIterator) Type() string { return "and" }