trie

package
v0.0.0-...-8c8dd33 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

package trie provides a trie implementation for representing words as a sequence of runes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

type Trie struct {
	// IsEnd represents that this node is the end of a valid word.
	IsEnd bool

	// Branches is a map of rune to next node in the Trie representing
	// that rune.
	Branches map[rune]*Trie
}

Trie is a single node in a Trie representing words. The rune for each node is not included in the node itself as it is used for the map lookup/branch.

func (*Trie) AddWord

func (t *Trie) AddWord(word []rune)

AddWord adds a new word to a Trie.

func (*Trie) Contains

func (t *Trie) Contains(word []rune) bool

Contains checks if a word exists in a Trie.

func (*Trie) IsEmpty

func (t *Trie) IsEmpty() bool

IsEmpty returns true if t has no Branches.

func (*Trie) Print

func (t *Trie) Print(writer io.Writer)

Print all words in Trie in alphabetical order.

func (*Trie) ReadWords

func (t *Trie) ReadWords(reader io.Reader) ([]rune, error)

ReadWords fills a Trie with words from a file, one per line, and returns a slice of all runes contained in the file and an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL