Documentation
¶
Overview ¶
Package trie implements a simple prefix tree. This is designed to be used for text command completion and is reasonably efficient in that application.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// Val is the value of the node if it's terminal, otherwise it will be
// nil.
Val any
// contains filtered or unexported fields
}
Node represents an entire prefix tree or a node within it.
func (*Node) Children ¶
Children returns the immediate child nodes optionally sorted in alphabetical order.
func (*Node) Find ¶
Find returns the node that completes the key as much as possible while remaining unique. The key is split by sep and each part is completed individually.
func (Node) String ¶
String returns a pretty-printed string of the node and all its children.
Example ¶
n := testTree() fmt.Println(n.String())
Output: `--(*) `--(?) => "?": <value for "?"> `--(a) | `--(r) | `--(c) | `--(h) | `--(i) | `--(v) | `--(e) => "archive": <value for "archive"> `--(c) | `--(o) | `--(n) | `--(d) | `--(i) | `--(t) | `--(i) | `--(o) | `--(n) | `--(s) => "conditions": <value for "conditions"> `--(d) | `--(a) | `--(t) | `--(e) => "date": <value for "date"> `--(e) | `--(x) | `--(i) | `--(t) => "exit": <value for "exit"> `--(h) | `--(e) | `--(a) | | `--(l) | | `--(t) | | `--(h) => "health": <value for "health"> | `--(l) | `--(p) => "help": <value for "help"> `--(l) | `--(a) | | `--(m) | | `--(p) | | `--(s) | | `--( ) | | `--(o) | | `--(f) | | | `--(f) => "lamps off": <value for "lamps off"> | | `--(n) => "lamps on": <value for "lamps on"> | `--(o) | `--(g) | | `--(o) | | `--(u) | | `--(t) => "logout": <value for "logout"> | `--(o) | `--(p) => "loop": <value for "loop"> `--(q) | `--(u) | `--(i) | `--(t) => "quit": <value for "quit"> `--(t) | `--(i) | | `--(m) | | `--(e) => "time": <value for "time"> | `--(r) | `--(e) | `--(n) | `--(d) => "trend": <value for "trend"> `--(u) | `--(n) | | `--(a) | | `--(m) | | `--(e) => "uname": <value for "uname"> | `--(p) | `--(t) | `--(i) | `--(m) | `--(e) => "uptime": <value for "uptime"> `--(v) | `--(e) | `--(r) | `--(s) | `--(i) | `--(o) | `--(n) => "version": <value for "version"> `--(w) `--(a) | `--(t) | `--(c) | `--(h) | `--( ) | `--(c) | | `--(o) | | `--(n) | | `--(d) | | `--(i) | | `--(t) | | `--(i) | | `--(o) | | `--(n) | | `--(s) => "watch conditions": <value for "watch conditions"> | `--(l) | `--(o) | `--(g) | | `--( ) | | `--(d) | | | `--(e) | | | `--(b) | | | `--(u) | | | `--(g) => "watch log debug": <value for "watch log debug"> | | `--(t) | | `--(r) | | `--(a) | | `--(c) | | `--(e) => "watch log trace": <value for "watch log trace"> | `--(o) | `--(p) | `--(s) => "watch loops": <value for "watch loops"> `--(h) `--(o) `--(a) `--(m) `--(i) => "whoami": <value for "whoami">
Click to show internal directories.
Click to hide internal directories.