radix

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2018 License: Apache-2.0 Imports: 2 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

func NewFromMap

func NewFromMap(m map[string]interface{}) *Tree

NewFromMap returns a new tree containing the keys from an existing map

func (*Tree) Delete

func (t *Tree) Delete(s string) (interface{}, bool)

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

func (*Tree) DeletePrefix

func (t *Tree) DeletePrefix(s string) int

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) Get

func (t *Tree) Get(s string) (interface{}, 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 interface{}) (interface{}, bool)

Insert is used to add a newentry or update an existing entry. Returns if updated.

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, interface{}, bool)

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

func (*Tree) Maximum

func (t *Tree) Maximum() (string, interface{}, bool)

Maximum is used to return the maximum value in the tree

func (*Tree) Minimum

func (t *Tree) Minimum() (string, interface{}, bool)

Minimum is used to return the minimum value in the tree

func (*Tree) ToMap

func (t *Tree) ToMap() map[string]interface{}

ToMap is used to walk the tree and convert it into a map

func (*Tree) Walk

func (t *Tree) Walk(fn WalkFn)

Walk is used to walk the tree

func (*Tree) WalkPath

func (t *Tree) WalkPath(path string, fn WalkFn)

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) WalkPrefix

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

WalkPrefix is used to walk the tree under a prefix

type WalkFn

type WalkFn func(s string, v interface{}) bool

WalkFn is used when walking the tree. Takes a key and 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