Documentation ¶
Overview ¶
Package radix is an implementation of a radix tree.
It has the three basic operations (insertion, lookup and deletion) plus some additional methods, notably one that allows a dynamic lookup based on delimiters, which works similar to a named parameter functionality in HTTP routers.
Index ¶
- Constants
- type Node
- type SortingTechnique
- type Tree
- func (tr *Tree) Add(label string, v interface{})
- func (tr *Tree) Del(label string)
- func (tr *Tree) Get(label string) (*Node, map[string]string)
- func (tr *Tree) Len() int
- func (tr *Tree) SetBoundaries(placeholder, delim byte)
- func (tr *Tree) Size() int
- func (tr *Tree) Sort(st SortingTechnique)
- func (tr *Tree) String() string
Examples ¶
Constants ¶
const ( // Tsafe activates thread safety. Tsafe = 1 << iota // Tdebug adds more information to the tree's string representation. Tdebug // Tbinary uses a binary PATRICIA tree instead of a prefix tree. Tbinary // Tnocolor disables colorful output. Tnocolor )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { Value interface{} // contains filtered or unexported fields }
Node is a node of a radix tree.
type SortingTechnique ¶ added in v0.3.0
type SortingTechnique uint8
SortingTechnique is the technique used to sort the tree.
const ( // AscLabelSort is the value for sorting // the tree's edges by label in ascending order. AscLabelSort SortingTechnique = iota // DescLabelSort is the value for sorting // the tree's edges by label in descending order. DescLabelSort // PrioritySort is the value for sorting // the tree's edges by the priority of their nodes. PrioritySort )
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a radix tree.
Example ¶
package main import ( "fmt" "github.com/gbrlsnchs/radix" ) func main() { tr := radix.New(radix.Tdebug) tr.Add("romane", 1) tr.Add("romanus", 2) tr.Add("romulus", 3) tr.Add("rubens", 4) tr.Add("ruber", 5) tr.Add("rubicon", 6) tr.Add("rubicundus", 7) fmt.Printf("%v\n", tr) }
Output:
func (*Tree) Del ¶
Del deletes a node.
If a parent node that holds no value ends up holding only one edge after a deletion of one of its edges, it gets merged with the remaining edge.
func (*Tree) Len ¶ added in v1.0.0
Len returns the total numbers of nodes, including the tree's root.
func (*Tree) SetBoundaries ¶ added in v1.0.0
SetBoundaries sets a placeholder and a delimiter for the tree to be able to search for named labels.
func (*Tree) Sort ¶ added in v0.2.0
func (tr *Tree) Sort(st SortingTechnique)
Sort sorts the tree nodes and its children recursively according to their priority lengther.