radixtree

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package radixtree implements a tree lookup for values associated to paths.

This package is a fork of https://github.com/dimfeld/httptreemux.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPath          = errors.New("invalid path")
	ErrNotFound             = errors.New("not found")
	ErrFailedToDelete       = errors.New("failed to delete")
	ErrConstraintsViolation = errors.New("constraints violation")
)

Functions

This section is empty.

Types

type AddOption

type AddOption[V any] func(n *Tree[V])

func WithBacktracking

func WithBacktracking[V any](flag bool) AddOption[V]

type ConstraintsFunc

type ConstraintsFunc[V any] func(oldValues []V, newValue V) bool

type Entry

type Entry[V any] struct {
	Value      V
	Parameters map[string]string
}

type LookupMatcher

type LookupMatcher[V any] interface {
	// Match should return true if the value should be returned by the lookup.
	Match(value V, keys, values []string) bool
}

LookupMatcher is used for additional checks while performing the lookup of values in the spanned tree.

type LookupMatcherFunc

type LookupMatcherFunc[V any] func(value V, keys, values []string) bool

The LookupMatcherFunc type is an adapter to allow the use of ordinary functions as match functions. If f is a function with the appropriate signature, LookupMatcherFunc(f) is a LookupMatcher that calls f.

func (LookupMatcherFunc[V]) Match

func (f LookupMatcherFunc[V]) Match(value V, keys, values []string) bool

Match calls f(value).

type Option

type Option[V any] func(n *Tree[V])

func WithValuesConstraints

func WithValuesConstraints[V any](constraints ConstraintsFunc[V]) Option[V]

type Tree

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

func New

func New[V any](opts ...Option[V]) *Tree[V]

func (*Tree[V]) Add

func (n *Tree[V]) Add(path string, value V, opts ...AddOption[V]) error

func (*Tree[V]) Clone

func (n *Tree[V]) Clone() *Tree[V]

func (*Tree[V]) Delete

func (n *Tree[V]) Delete(path string, matcher ValueMatcher[V]) error

func (*Tree[V]) Empty

func (n *Tree[V]) Empty() bool

func (*Tree[V]) Find

func (n *Tree[V]) Find(path string, matcher LookupMatcher[V]) (*Entry[V], error)

type ValueMatcher

type ValueMatcher[V any] interface {
	// Match should return true if the value should be deleted from the tree.
	Match(value V) bool
}

ValueMatcher is used for additional checks while deleting of values in the spanned tree.

type ValueMatcherFunc

type ValueMatcherFunc[V any] func(value V) bool

The ValueMatcherFunc type is an adapter to allow the use of ordinary functions as match functions. If f is a function with the appropriate signature, ValueMatcherFunc(f) is a ValueMatcher that calls f.

func (ValueMatcherFunc[V]) Match

func (f ValueMatcherFunc[V]) Match(value V) bool

Match calls f(value).

Jump to

Keyboard shortcuts

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