https://github.com/maknahar/trie
Thread Safe Implementation of Trie Data Structure in Go
https://github.com/maknahar/trie
data-structures golang tree-structure trie
Last synced: 2 months ago
JSON representation
Thread Safe Implementation of Trie Data Structure in Go
- Host: GitHub
- URL: https://github.com/maknahar/trie
- Owner: maknahar
- License: mit
- Created: 2018-01-04T20:15:59.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-20T15:02:35.000Z (about 8 years ago)
- Last Synced: 2024-06-20T15:54:31.658Z (almost 2 years ago)
- Topics: data-structures, golang, tree-structure, trie
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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][1].
[1]: https://godoc.org/github.com/maknahar/trie
# 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.