Package radixrouter

import "github.com/byte-mug/golibs/radixroute"

Overview

A radix-tree router for URLs/Paths.

Index

type Parameter

type Parameter struct {
	Name	string
	Value	[]byte
}

-

type ParameterSetter

type ParameterSetter func(key string, value interface{})

-

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 (*Tree) Delete

func (t *Tree) Delete(s []byte) (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 []byte) 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 []byte, ps ParameterSetter) (rv interface{}, rok bool)

Get is used to perform a lookup in the route.

func (*Tree) GetParlist

func (t *Tree) GetParlist(s []byte, par []Parameter) (rv interface{}, rpar []Parameter, rok bool)

GetParlist is used to perform a lookup in the route.

func (*Tree) InsertParameter

func (t *Tree) InsertParameter(s []byte, name string, cc byte) *Tree

Inserts a new Parameter and returns the subtree. If the subtree already existed AND name or cc differ, it panics.

func (*Tree) InsertRaw

func (t *Tree) InsertRaw(s []byte, v interface{}) (interface{}, bool)

Maunually inserts a record into the radix tree.

func (*Tree) InsertRoute

func (t *Tree) InsertRoute(s []byte, v interface{}) (interface{}, bool)

InsertRoute insert a new route. If it overwrote the route, it returns (old-value,true) otherwise (nil,false).

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 []byte) ([]byte, 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() ([]byte, interface{}, bool)

Maximum is used to return the maximum value in the tree

func (*Tree) Minimum

func (t *Tree) Minimum() ([]byte, interface{}, bool)

Minimum is used to return the minimum value in the tree

func (*Tree) Walk

func (t *Tree) Walk(fn WalkFn)

Walk is used to walk the tree

func (*Tree) WalkPath

func (t *Tree) WalkPath(path []byte, 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 []byte, fn WalkFn)

WalkPrefix is used to walk the tree under a prefix

type WalkFn

type WalkFn func(s []byte, v interface{}) bool

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

Dependencies