pathtrie

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pathtrie provides a minimal implementation of a trie where each node is a path component, allowing you to efficiently store metadata about a path-based structure and iterate over subtrees within said structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathTrie

type PathTrie[V any] struct {
	// contains filtered or unexported fields
}

PathTrie represents a trie with each node being a path component.

func NewTrie

func NewTrie[V any]() *PathTrie[V]

NewTrie returns a new empty PathTrie.

func (*PathTrie[V]) Delete

func (t *PathTrie[V]) Delete(path string) (old V, found bool)

Delete removes the value at the given path, but any child entries are kept as-is. To remove the entry and all child entries use [DeleteAll]. If there was a value at the given path, the old value is returned and found will be true.

func (*PathTrie[V]) DeleteAll

func (t *PathTrie[V]) DeleteAll(path string) (old V, found bool)

DeleteAll removes the entry at the given path and all child entries. To only delete the value at the path use [Delete]. If there was a value at the given path, the old value is returned and found will be true.

func (*PathTrie[V]) Get

func (t *PathTrie[V]) Get(path string) (val V, found bool)

Get looks up the given path in the trie. Completely non-existent paths and paths with no value (such as intermediate paths) are considered the same.

func (*PathTrie[V]) Set

func (t *PathTrie[V]) Set(path string, value V) (old V, found bool)

Set adds a new value to the trie at the given path with the given value. If there was a value at the given path, the old value is returned and found will be true.

func (*PathTrie[V]) WalkFrom

func (t *PathTrie[V]) WalkFrom(path string, walkFn WalkFunc[V]) error

WalkFrom does a depth-first walk of the trie starting at the given path. The exact order of execution is not guaranteed to be the same each time (as node children are stored as maps).

type WalkFunc

type WalkFunc[V any] func(path string, value V) error

WalkFunc is the callback function called by [WalkFrom].

Jump to

Keyboard shortcuts

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