trie: Index | Examples | Files

package trie

import ""



Package Files


type Iter Uses

type Iter func(r rune, n Node)

Iter is a function type used as an argument to ForEach. It's arguments are the same as what would be returned on each for loop cycle, namely a rune and a map of nodes.

type Node Uses

type Node map[rune]Node

The Node type makes up the Trie data structure.


trie := New()
trie.Index([]string{"ab", "ac", "ad", "abc"})
fmt.Printf("%q", trie.Search("ab"))


["ab" "abc"]

func New Uses

func New() Node

New allocates a new node.

func (Node) All Uses

func (node Node) All(p string) (res []string)

All returns all the strings indexed by the current node and it's children in an array each item prefixed by p.

func (Node) ForEach Uses

func (node Node) ForEach(f Iter)

ForEach wraps the for loop and additionally checks for the end rune and ignores it.

func (Node) Index Uses

func (node Node) Index(d []string)

Index builds a Trie with the supplied dictionary d.

func (Node) Insert Uses

func (node Node) Insert(s string)

Insert adds a new word to the Trie. It iterates over s and creates or appends a new Node for each rune.

func (Node) IsEnd Uses

func (node Node) IsEnd() bool

IsEnd returns true if the current node is an end node.

func (Node) Search Uses

func (node Node) Search(s string) (res []string)

Search looks for the string s inside the Trie structure. If s is matched and the node has mode children, its children are also returned as they all match the given prefix s.

func (Node) String Uses

func (node Node) String() string

String satisfies the Stringer interface for easily printing a Trie.

Package trie imports 3 packages (graph). Updated 2017-08-31. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).