tree

package module
v0.0.0-...-fc4206c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package tree implements a tree structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Path

type Path []string

Path is the path of an element in the tree.

type PathValue

type PathValue struct {
	Path  Path
	Value interface{}
}

PathValue represents a value stored at a certain path in the tree.

type Tree

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

Tree structure storing values at paths. It is not safe for concurrent use by multiple goroutines without locking.

func (*Tree) All

func (t *Tree) All(prefix Path) []PathValue

All returns all items stored in the tree under the given prefix.

func (*Tree) Clone

func (t *Tree) Clone() *Tree

Clone returns a clone of the tree.

func (*Tree) Delete

func (t *Tree) Delete(p Path) (val interface{}, deleted bool)

Delete deletes the value stored in the tree under the given path, if it exists. It returns the deleted value if it was deleted.

func (*Tree) Load

func (t *Tree) Load(p Path) (val interface{}, ok bool)

Load returns the value stored in the tree under the given path, if it exists.

func (*Tree) LoadOrStore

func (t *Tree) LoadOrStore(p Path, val interface{}) (actual interface{}, loaded bool)

LoadOrStore returns the value stored in the tree under the given path, if it exists. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*Tree) Store

func (t *Tree) Store(p Path, val interface{}) (old interface{}, replaced bool)

Store stores the given value in the tree under the given path. It returns the old value if an existing value was replaced.

func (*Tree) Walk

func (t *Tree) Walk(prefix Path, f WalkFunc) error

Walk walks the tree under the given prefix. If f returns a non-nil error, walk stops and returns that error.

type WalkFunc

type WalkFunc func(p Path, val interface{}) error

WalkFunc is called by Walk.

Jump to

Keyboard shortcuts

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