trie

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Char        string
	Children    [26]*Node
	IsEndOfWord bool
	// contains filtered or unexported fields
}

Node represents a single character in the trie. Char is the string repersentation of the character Each node has 26 childe nodes which represent each letter of the alphabet.

func NewNode

func NewNode(char string) *Node

NewNode is used to initialize a new node with it's 26 children and each child should first be initialized to nil

type Trie

type Trie struct {
	RootNode *Node
}

Trie is the tree that will hold all of the nodes. RootNode is always nil.

func NewTrie

func NewTrie() *Trie

NewTrie creates a new trie with a root. This node is not used to match words so it can be anything; ie "\000".

func (*Trie) Insert

func (t *Trie) Insert(fileName string) error

Insert inserts a word to the trie.

func (*Trie) Search

func (t *Trie) Search(prefix string) []string

func (*Trie) SearchWord

func (t *Trie) SearchWord(word string) bool

SearchWord will return false if the word is not in the trie and true if it is in th trie.

Jump to

Keyboard shortcuts

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