radix

package
v0.0.0-...-5d27ecb Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

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

Tree implements a radix tree. This can be treated as a Dictionary abstract data type. The main advantage over a standard hash map is prefix-based lookups and ordered iteration

func New

func New() *Tree

New returns an empty Tree with sane defaults

func (*Tree) Delete

func (t *Tree) Delete(s string) (Value, bool)

Delete is used to delete a key, returns the previous value and if it was deleted

func (*Tree) Get

func (t *Tree) Get(s string) (Value, bool)

Get is used to lookup a specific key, returning the value and if it was found

func (*Tree) Insert

func (t *Tree) Insert(s string, v Value) (Value, bool, error)

Insert is used to add or update a new entry into the Tree. Returns true if the Tree was updated Returns error if there is an error replacing an edge. If this happens, the tree is considered broken.

func (*Tree) Len

func (t *Tree) Len() int

Len is used to return the number of elements in the tree

func (*Tree) LongestPrefix

func (t *Tree) LongestPrefix(s string) (string, Value, bool)

LongestPrefix is like Get, but instead of an exact match, it will return the longest prefix match.

func (*Tree) Walk

func (t *Tree) Walk(fn WalkFn)

Walk is used to walk the tree

func (*Tree) WalkPrefix

func (t *Tree) WalkPrefix(prefix string, fn WalkFn)

WalkPrefix is used to walk the tree under a prefix

type Value

type Value interface{}

Value represents the value to be stored in the radix tree

type WalkFn

type WalkFn func(string, Value) bool

WalkFn is used when walking the tree. It takes a key and a value, returning if iteration should be terminated.

Jump to

Keyboard shortcuts

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