AR-Trie Package
โข
1 minute read
Overview
A Go library implementing a Trie data structure supporting rune type, enabling work with Arabic and English letters.
Available Functions
- InitTrie - initialize the tree
- Insert - insert a single key
- Find - check if key exists
- Put - associate key with value
- Get - retrieve key value
- Delete - remove a key
- Search - search using prefix
Performance (Benchmark)
BenchmarkInsert-12 2260291 523.4 ns/op 2 B/op 0 allocs/op
BenchmarkFind-12 152889574 7.304 ns/op 0 B/op 0 allocs/op
BenchmarkPut-12 2127642 561.2 ns/op 10 B/op 1 allocs/op
BenchmarkGet-12 169333138 7.154 ns/op 0 B/op 0 allocs/op
BenchmarkKeys-12 117835408 9.887 ns/op 0 B/op 0 allocs/op
BenchmarkSearch-12 28626381 102.2 ns/op 16 B/op 1 allocs/op
Usage Examples
tr := InitTrie()
tr.Insert("mohamed")
tr.Insert("ู
ุญู
ุฏ")
tr.Insert("ู
ุญู
ูุฏ")
tr.Keys("ู
ุญ") // [ู
ุญู
ุฏ ู
ุญู
ูุฏ]
Quick Start
go get github.com/mohamedelhefni/ar-trie
package main
import (
"fmt"
trie "github.com/mohamedelhefni/ar-trie"
)
func main() {
tr := trie.InitTrie()
tr.Insert("mohamed")
tr.Insert("mahmoud")
fmt.Println(tr.Find("mohamed")) // true
fmt.Println(tr.Search("mo")) // [mohamed mahmoud]
}