Skip to content

maximdanilchenko/go-trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-trie

Package go-trie implements trie tree (or prefix tree) data structure useful for things like prefix search/autocompletion.

For now, it supports Insert, HasWord, HasPrefix and WordsByPrefix methods. WordsByPrefix collects all words with given prefix without usage of recursion while search.

tree := NewTrie()

t.Insert("go", "golang", "gopher", "python", "pythonista", "grow", "gg", "glitch", "glass")

hasPrefix := tree.HasPrefix("gol") // return true
hasPrefix = tree.HasPrefix("gene") // return false

hasWord := tree.HasWord("gopher") // return true
hasWord = tree.HasWord("foo") // return false

words := tree.WordsByPrefix("go") // return []string{"go", "gopher", "golang"}

About

Package trie implements trie tree (or prefix tree) data structure useful for things like prefix search/autocompletion

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages