An open API service indexing awesome lists of open source software.

https://github.com/karrick/gotrie

Go library that implements a Trie data structure.
https://github.com/karrick/gotrie

data-structures golang golang-library

Last synced: 9 months ago
JSON representation

Go library that implements a Trie data structure.

Awesome Lists containing this project

README

          

# gotrie

Go library that implements a Trie data structure.

[![GoDoc](https://godoc.org/github.com/karrick/gotrie?status.svg)](https://godoc.org/github.com/karrick/gotrie)

## Example

```Go
package main

import (
"bufio"
"fmt"
"os"

"github.com/karrick/gotrie"
)

func main() {
// build a new Trie from standard input lines
t := gotrie.NewPrefixTrie()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
t.Insert(scanner.Text(), struct{}{})
}

if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
os.Exit(1)
}

// Enumerate through Trie in sorted order
for t.Scan() {
fmt.Println(t.Text())
}
}
```