robindiddams / go-trie

a zero dependency rune trie written in pure go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-trie

Go Reference

This is a trie in go. I use maps so it's not the most memory efficient, but it does the job. The purpose of this was mainly for parsing emojis out of text. Since the number of unicode codepoints for a single emoji is 1-n and some emojis are subsets of other emojis this makes parsing them for the purpose of extracting them very tricky and ideal for a trie.

Example

import "github.com/robindiddams/go-trie"

// create a trie with some string search values
myTrie := trie.NewTrieString("foo", "bar", "foobar", "one")

// search a string for string matches
results := myTrie.SearchString("there should be one foo, one bar, one foobar, and four 'one's in this string")
// results == [one foo one bar one foobar one]

Notice how it doesn't match the foo (or the bar) inside foobar, the trie will always match the maximum (ie. longest) search value. This is the magic of tries 🧙‍♂️

PRs welcome (especially ones with emojis 🙌)!

About

a zero dependency rune trie written in pure go

License:MIT License


Languages

Language:Go 100.0%