Replace DebugString with Describe

This change makes tree description completely open to mechanical
analysis and ensures consistency between description formats for each of
the iterator types.

Renamed StatsContainer.(Kind -> Type) for consistency.
This commit is contained in:
kortschak 2014-09-05 09:05:02 +09:30
parent b5f113203d
commit 62013d3dfc
22 changed files with 186 additions and 162 deletions

View file

@ -17,6 +17,7 @@ package graph
// Define the general iterator interface.
import (
"github.com/google/cayley/quad"
"strings"
"sync"
@ -130,8 +131,8 @@ type Iterator interface {
// Return a slice of the subiterators for this iterator.
SubIterators() []Iterator
// Return a string representation of the iterator, indented by the given amount.
DebugString(int) string
// Return a string representation of the iterator.
Describe() Description
// Close the iterator and do internal cleanup.
Close()
@ -140,6 +141,17 @@ type Iterator interface {
UID() uint64
}
type Description struct {
UID uint64 `json:",omitempty"`
Name string `json:",omitempty"`
Type string `json:",omitempty"`
Tags []string `json:",omitempty"`
Size int64 `json:",omitempty"`
Direction quad.Direction `json:",omitempty"`
Iterator *Description `json:",omitempty"`
Iterators []Description `json:",omitempty"`
}
type Nexter interface {
// Next advances the iterator to the next value, which will then be available through
// the Result method. It returns false if no further advancement is possible.
@ -256,16 +268,16 @@ func (t Type) String() string {
}
type StatsContainer struct {
UID uint64
Type string
IteratorStats
Kind string
UID uint64
SubIts []StatsContainer
}
func DumpStats(it Iterator) StatsContainer {
var out StatsContainer
out.IteratorStats = it.Stats()
out.Kind = it.Type().String()
out.Type = it.Type().String()
out.UID = it.UID()
for _, sub := range it.SubIterators() {
out.SubIts = append(out.SubIts, DumpStats(sub))