Documentation
¶
Overview ¶
Package radix implements a generic radix tree. This is based primarily on this original implementation in this project:
https://github.com/armon/go-radix
The original was not generic, but this one is. I also cut out some extraneous operations I didn't feel I needed.
Index ¶
- type Tree
- func (tree *Tree[T]) Delete(s string) (T, bool)
- func (tree *Tree[T]) DeletePrefix(s string) int
- func (tree *Tree[T]) Get(s string) (T, bool)
- func (tree *Tree[T]) Insert(s string, v T) (T, bool)
- func (tree *Tree[T]) Len() int
- func (tree *Tree[T]) LongestPrefix(s string) (string, T, bool)
- func (tree *Tree[T]) Maximum() (string, T, bool)
- func (tree *Tree[T]) Minimum() (string, T, bool)
- func (tree *Tree[T]) Walk(fn WalkFunc[T])
- func (tree *Tree[T]) WalkPath(path string, fn WalkFunc[T])
- func (tree *Tree[T]) WalkPrefix(prefix string, fn WalkFunc[T])
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
Tree implements a radix tree. It's a map-like structure that lets you efficiently find exact instances of keys as well as anything matching prefixes.
func (*Tree[T]) Delete ¶
Delete is used to remove a node from the tree, returning the previous value and if it was deleted.
func (*Tree[T]) DeletePrefix ¶
DeletePrefix is used to delete the subtree under a prefix Returns how many nodes were deleted Use this to delete large subtrees efficiently
func (*Tree[T]) Get ¶
Get is used to look up a specific key, returning the value and if it was found.
func (*Tree[T]) Insert ¶
Insert is used to add a new entry or update an existing entry. Returns true if an existing record is updated.
func (*Tree[T]) LongestPrefix ¶
LongestPrefix is like Get, but instead of an exact match, it will return the longest prefix match.
func (*Tree[T]) Walk ¶
Walk visits every not in the tree, invoking your callback function for each one.
func (*Tree[T]) WalkPath ¶
WalkPath is used to walk the tree, but only visiting nodes from the root down to a given leaf. Where WalkPrefix walks all the entries *under* the given prefix, this walks the entries *above* the given prefix.
func (*Tree[T]) WalkPrefix ¶
WalkPrefix is used to visit just the nodes whose key starts with the given prefix.