Skip to content
/ trie Public

Thread Safe Implementation of Trie Data Structure in Go

License

Notifications You must be signed in to change notification settings

maknahar/trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trie

Go Implementation of a Thread Safe Trie Data Structure and (some of) Trie Operations

trie := New().Insert("foo", "bar", "baz")

trie.PrefixSearch("fo")                 // returns true
trie.PrefixSearch("fb")                 // returns false
trie.Search("fo")                       // returns false
trie.Search("foo")                      // returns true

Code documentation can be found here.

Supported Operation

Operations on Trie Data Structure Level

  • New() *Trie

    Creates an initialized trie data structure

  • Insert(keywords ...string)

    Insert allow one or more keyword to be inserted in trie. keyword can be any valid Unicode string

  • PrefixSearch(Key string) (found bool)

    Search checks if keyword exist in trie as a keyword or prefix to keyword

  • Search(keyword string) (found bool)

    PrefixSearch checks if keyword exist in trie as a fully qualified keyword.

  • Delete(keyword string)

    Delete deletes a keyword from a trie if keyword exist in trie

  • DeleteBranch(key string)

    DeleteBranch deletes all child after last letter of key if key exists in trie. If key is found, key will be treated as a keyword after this operation

Operations on Node Level

  • CreateNode(v rune) *Node

    CreateNode returns an initialized trie node

  • AddChildNode(v rune) *Node

    AddChildNode add child node to current node with value v

  • Len() int

    Len returns the number of children for node

  • IsLeafNode() bool

    IsLeafNode returns true if current node is a leaf node in Trie

  • GetChildNode(v rune) (node *Node, exist bool)

    GetChildNode retrieve child node with value v.

  • DeleteChildNode(v rune)

    DeleteChildNode Deletes the child node if it exist

Your ideas and suggestions are always welcome. Either in form of issues or Pull Requests.

About

Thread Safe Implementation of Trie Data Structure in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages