treesteps

package
v2.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRecording

func IsRecording(n Node) bool

IsRecording indicates whether a recording involving a given node is currently in progress. Can be used as a fast check before calling StartOpf.

func NodeUpdated

func NodeUpdated(n Node, reason string)

NodeUpdated can be used to trigger a new step in any recording that involves the given node. It can be used when the state of the node changed in a significant way. The reason is optional and will show up in the step description.

func TreeToString

func TreeToString(n Node) string

TreeToString returns a string representation of the current state of a Node tree.

Types

type Node

type Node interface {
	TreeStepsNode() NodeInfo
}

Node must be implemnented by every node in the hierarchy.

type NodeInfo

type NodeInfo struct {
	// contains filtered or unexported fields
}

NodeInfo contains the information that we present for each node.

func NodeInfof

func NodeInfof(format string, args ...any) NodeInfo

NodeInfof returns a NodeInfo with the name initialized with a formatted string.

func (*NodeInfo) AddChildren

func (ni *NodeInfo) AddChildren(nodes ...Node)

AddChildren adds one or more children to the NodeInfo.

Any nil children are ignored (this includes nil pointers of any type).

func (*NodeInfo) AddPropf

func (ni *NodeInfo) AddPropf(key string, format string, args ...any)

AddPropf adds a property to the NodeInfo.

type Op

type Op struct {
	// contains filtered or unexported fields
}

Op represents an operation that is associated with a node.

func StartOpf

func StartOpf(node Node, format string, args ...any) *Op

StartOpf registers the start of a new operation on a node and emits a step. The operation will be displayed for the given node until FinishOpf is called.

If a recording involving the node is not currently in progress, does nothing and returns nil. Other methods can be called (and do nothing) when Op is nil.

Note: it is recommended that IsRecording() is checked first to avoid any allocations (e.g. due to boxing of args) in the normal, non-recording path.

func (*Op) Finishf

func (op *Op) Finishf(format string, args ...any)

Finishf changes the state of the operation, emits a step, and cleans up the operation.The state of the operation shows up after the details that were provided in StartOpf.

func (*Op) Updatef

func (op *Op) Updatef(format string, args ...any)

Updatef changes the state of the operation and emits a step. The state of the // operation shows up after the details that were provided in StartOpf.

type Recording

type Recording struct {
	// contains filtered or unexported fields
}

Recording captures the step-by-step propagation of operations. See StartRecording.

func StartRecording

func StartRecording(root Node, name string, opts ...RecordingOption) *Recording

StartRecording starts a new recording that captures step-by-step propagation of operations and changes in a hierarchical structure.

Each node in the structure must implement the TreeStepsNode method, which returns information about the current state of the node and a list of its children. For every operation or sub-operation on a node, StartOpf and FinishOpf must be called. Calling Finish() on the Recording will return all the collected information (which can be presented as text or as a link to a visualization).

It is not legal to start a recording that involves the same node as another in-progress recording (this applies to all nodes in the hierarchy).

See SegmentTree in tree_steps_test.go for an example.

func (*Recording) Finish

func (r *Recording) Finish() Steps

Finish completes the recording and returns the recorded steps.

type RecordingOption

type RecordingOption func(*Recording)

RecordingOption is an optional argument to StartRecording.

func MaxOpDepth

func MaxOpDepth(maxOpDepth int) RecordingOption

MaxOpDepth configures a recording to only show operations for nodes up to a certain depth. Operations and node updates below that level are ignored.

func MaxTreeDepth

func MaxTreeDepth(maxTreeDepth int) RecordingOption

MaxTreeDepth configures a recording to only show trees up to a certain depth. Operations and node updates below that level are ignored.

type Step

type Step struct {
	Name string   `json:"name"`
	Root TreeNode `json:"tree"`
}

Step contains the tree for a single step in a recording.

type Steps

type Steps struct {
	Name  string
	Steps []Step `json:"steps"`
}

Steps contains the result of a recording: the full details of the hierarchy for each step.

func (Steps) String

func (s Steps) String() string

String returns the steps as a string (using treeprinter).

func (Steps) URL

func (s Steps) URL() url.URL

URL for a visualization of the steps. The URL contains the encoded and compressed data as the URL fragment.

type TreeNode

type TreeNode struct {
	Name       string      `json:"name"`
	Properties [][2]string `json:"props"`
	Ops        []string    `json:"ops"`
	Children   []TreeNode  `json:"children"`
}

TreeNode is a node in the tree for a step in a recording.

func (*TreeNode) String

func (t *TreeNode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL