tree

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// ID is a unique identifier for the node.
	ID string
	// Name is the display name of the node.
	Name string
	// Properties contains a list of key-value properties associated with the node.
	Properties []Property
	// Children are child nodes of the node.
	Children []*Node
	// Comments, like Children, are child nodes of the node, with the difference
	// that comments are indented a level deeper than children. A common use-case
	// for comments are tree-style properties of a node, such as expressions of a
	// physical plan node.
	Comments []*Node
}

Node represents a node in a tree structure that can be traversed and printed by the Printer. It allows for building hierarchical representations of data where each node can have multiple properties and multiple children.

func NewNode

func NewNode(name, id string, properties ...Property) *Node

NewNode creates a new node with the given name, unique identifier and properties.

func (*Node) AddChild

func (n *Node) AddChild(name, id string, properties []Property) *Node

AddChild creates a new node with the given name, unique identifier, and properties and adds it to the parent node.

func (*Node) AddComment

func (n *Node) AddComment(name, id string, properties []Property) *Node

type Printer

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

Printer is used for writing the hierarchical representation of a tree of [Node]s.

func NewPrinter

func NewPrinter(w io.StringWriter) *Printer

NewPrinter creates a new Printer instance that writes to the specified io.StringWriter.

func (*Printer) Print

func (tp *Printer) Print(root *Node)

Print writes the entire tree structure starting from the given root node to the printer's io.StringWriter. Example output:

SortMerge #sort order=ASC column=timestamp
├── Limit #limit1 limit=1000
│   └── DataObjScan #scan1 location=dataobj_1
└── Limit #limit2 limit=1000
    └── DataObjScan #scan2 location=dataobj_2

type Property

type Property struct {
	// Key is the name of the property.
	Key string
	// Values holds the value(s) of the property.
	Values []any
	// IsMultiValue marks whether the property is a multi-value property.
	IsMultiValue bool
}

Property represents a property of a Node. It is a key-value-pair, where the value is either a single value or a list of values. When the value is a multi-value, the field IsMultiValue needs to be set to `true`. A single-value property is represented as `key=value` and a multi-value property as `key=(value1, value2, ...)`.

func NewProperty

func NewProperty(key string, multi bool, values ...any) Property

NewProperty creates a new Property with the specified key, multi-value flag, and values. The multi parameter determines if the property should be treated as a multi-value property.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳