Help us shape the future of Go! Take the 2026 Go Developer Survey

dictionary

package module
v0.0.0-...-229cf68 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2016 License: Unlicense Imports: 4 Imported by: 7

README

dictionary

A simple wrapper around the unix words file

GoDoc

Documentation

Overview

Package dictionary provides utilities for working with dictionary words.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDictionaryNotFound is an error returned when the default system dictionary
	// cannot be found or loaded.
	DefaultDictionaryNotFound = errors.New("Unable to find default dictionary")
)

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Contains determines if the provided word is contained within the dictionary.
	Contains(string) bool

	// Words returns a slice of all of the words contained in the dictionary.
	Words() []string
}

Interface defines the interface that all dictionaries implement.

func Default

func Default() (Interface, error)

Default returns the default dictionary on Unix systems.

func Filter

func Filter(source Interface, filterFunc func(string) bool) Interface

Filter creates a new dictionary only containing words for which filterFunc returns true.

func Load

func Load(filename string) (Interface, error)

Load loads a dictionary from a file containing newline separated words.

func WithWords

func WithWords(words ...string) Interface

WithWords creates a new dictionary with the provided words.

type PrefixTree

type PrefixTree struct {
	Valid bool
	// contains filtered or unexported fields
}

PrefixTree is a prefix tree/trie implementation that can be constructed from a dictionary.Interface.

func BuildPrefixTree

func BuildPrefixTree(d Interface) *PrefixTree

BuildPrefixTree contructs a new prefix tree from the provided dictionary.

func (*PrefixTree) Contains

func (t *PrefixTree) Contains(word string) bool

Contains returns true if the provided word is contained within the prefix tree.

func (*PrefixTree) Insert

func (t *PrefixTree) Insert(s string)

Insert inserts a new word into the prefix tree.

func (*PrefixTree) Next

func (t *PrefixTree) Next(c rune) *PrefixTree

Next returns a new prefix tree, rooted at the next character.

func (*PrefixTree) Words

func (t *PrefixTree) Words() (words []string)

Words returns a slice of all words contained within the prefix tree.

Jump to

Keyboard shortcuts

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