https://github.com/joway/trie
trie implement for golang
https://github.com/joway/trie
golang trie
Last synced: 10 months ago
JSON representation
trie implement for golang
- Host: GitHub
- URL: https://github.com/joway/trie
- Owner: joway
- License: mit
- Created: 2019-02-09T00:22:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-09T10:57:32.000Z (about 7 years ago)
- Last Synced: 2025-03-18T23:18:38.349Z (about 1 year ago)
- Topics: golang, trie
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Trie
[](https://goreportcard.com/report/github.com/joway/trie)
[](https://codecov.io/gh/joway/trie)
[](https://circleci.com/gh/joway/trie)
## Usage
### Prefix Search
```go
import "github.com/joway/trie"
dict := map[string]interface{}{
"/abc": "2",
"/a": "1",
"/ac": "3",
"/b": "4",
"/bc": "5",
"/bca": "6",
"/ba": "7",
"/cba": "8",
}
tree := trie.Build(dict)
prefix, val := tree.PrefixSearchString("/a")
```
### Prettify Output
```go
output := tree.Prettify()
fmt.Println(output)
```
```
*->/->a->b->c
|| | ->c
|| ->b->a
|| | ->c->a
|| ->c->b->a
```
## Document
[GoDoc](https://godoc.org/github.com/joway/trie)
## Benchmark
```
BenchmarkBuild-8 2000 814677 ns/op 555392 B/op 7377 allocs/op
BenchmarkTrie_AddWord-8 100000000 12.6 ns/op 0 B/op 0 allocs/op
BenchmarkTrie_PrefixSearchString-8 5000000 267 ns/op 32 B/op 1 allocs/op
BenchmarkTrie_PrefixSearch-8 10000000 156 ns/op 0 B/op 0 allocs/op
```
### Benchmark Comparison
[https://github.com/derekparker/trie](https://github.com/derekparker/trie)
```
BenchmarkTrie_AddWord_DTrie-8 20000000 108 ns/op 112 B/op 2 allocs/op
BenchmarkTrie_PrefixSearchString_DTrie-8 2000000 732 ns/op 160 B/op 9 allocs/op
```