Skip to content

A primitive implementation of the Trie data structure in Golang.

License

Notifications You must be signed in to change notification settings

alexanderbez/go-trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-trie

GoDoc Build Status Go Report Card

A primitive implementation of the Trie data structure in Golang. The Trie data structure allows for quick information retrieval, typically strings, and prefix searching. It stores data as an associative array. Keys and their respective values are stored as bytes.

Typically, values in a Trie are unnecessary, rather, they are not traditionally needed. In such cases such as these, you can simply store some terminal or constant value.

Usage

// Construct an empty trie with a single root node
trie := NewTrie()

// Insert a key value pair into the trie
trie.Insert([]byte("someKey"), []byte("someValue"))

// Search for some value
value, ok := trie.Search([]byte("someKey"))

// Get all keys stored in the trie
keys := trie.GetAllKeys()

// Get all values stored in the trie
values := trie.GetAllValues()

// Get all keys stored in the trie that contain a specific prefix
keyByPrefix := trie.GetPrefixKeys([]byte("somePrefix"))

// Get all values stored in the trie who's corresponding keys contain a
// specific prefix.
valuesByPrefix := trie.GetPrefixValues(prefix)

Tests

$ go test -v

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request

About

A primitive implementation of the Trie data structure in Golang.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages