pathtree

package
v0.1.47 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 6 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 {
	Key   string
	Value string
	Label string
	// contains filtered or unexported fields
}

type PrintOption

type PrintOption int

PrintOption determines what information about each Node is printed. The values of Key, Value, and Label were chosen to be relatively prime to make determining what combination of identifiers to print purely mathematical Actual output may vary depending on available identifiers for each Node.

const (
	Key           PrintOption = 2
	Value         PrintOption = 3
	Label         PrintOption = 5
	KeyValue      PrintOption = 6
	KeyLabel      PrintOption = 10
	ValueLabel    PrintOption = 15
	KeyValueLabel PrintOption = 30
)

func (PrintOption) String

func (po PrintOption) String() string

type Tree

type Tree struct {
	PrintOption PrintOption
	// contains filtered or unexported fields
}

func New

func New() *Tree

New returns a pointer to an initialized Tree

func (*Tree) Add

func (t *Tree) Add(key, value, label string) error

Add adds the given Value to the tree at the given Key path. If interior nodes between the root and leaf do not exist, empty nodes without a Value are created along the path. Add cannot be used to overwrite a Value that already exists at the given Key path.

func (*Tree) Contains

func (t *Tree) Contains(key string) bool

Contains returns true if Key is found in the tree, even if the Value is unset.

func (*Tree) Delete

func (t *Tree) Delete(key string) (string, error)

Delete deletes the Node identified by the given Key. Currently, only deleting leaves is supported.

func (*Tree) Flatten

func (t *Tree) Flatten() []*Node

func (*Tree) Fprint

func (t *Tree) Fprint(w io.Writer)

Fprint prints the tree to the writer.

func (*Tree) Get

func (t *Tree) Get(key string) (string, error)

Get returns the Value in the Tree stored at the given Key path. If no Value was stored but the Key exists, return the local portion of the Key path.

func (*Tree) SetPrefix

func (t *Tree) SetPrefix(prefix string)

func (*Tree) String

func (t *Tree) String() string

String returns the tree as a string.

func (*Tree) Update

func (t *Tree) Update(key, value, label string) error

Update updates the Node at the given Key location, if it exists. Returns an error if any ancestor Node does not exist (since that implies the Node at Key does not exist yet).

Jump to

Keyboard shortcuts

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