Documentation ¶
Overview ¶
Package pathtree provides a data structure that stores values organized under a tree-like hierarchy where values from higher levels cascade down to lower levels unless the lower levels define their own values.
For example, if 'foo/bar' defines a value X, foo/bar, foo/bar/baz, and foo/bar/qux and all their descendants inherit this value.
t.Set("foo/bar", X) t.Get("foo/bar") // == X t.Get("foo/bar/baz") // == X t.Get("foo/bar/qux") // == X
However, if 'foo/bar/baz' defines a different value Y, it and its descendants use that value.
t.Set("foo/bar", X) t.Set("foo/bar/baz", Y) t.Get("foo/bar") // == X t.Get("foo/bar/qux") // == X t.Get("foo/bar/baz") // == Y t.Get("foo/bar/baz/qux") // == Y
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Root ¶
type Root[T any] struct { // contains filtered or unexported fields }
Root is the starting point of the path tree. The zero-value of Root is an empty tree.
func (*Root[T]) Lookup ¶
Lookup retrieves the value for the given path, inheriting values specified for parents of this path if it didn't get its own value.
Lookup reports true if a value was found--even if it was inherited.
type Snapshot ¶
type Snapshot[T any] struct { // Value in the tree, // or nil if this node doesn't have an explicit value. Value *T // Path to this node. Path string // Children of this node. Children []Snapshot[T] }
Snapshot is a snapshot of values added to the tree presented in a hierarchical manner.