Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

README.md

0.92 Kb · 44 lines

Trie Package

Package implements a simple prefix-tree (trie) for Gno realms, keyed by string with values of any type.

Tree implements the avl.ITree interface from gno.land/p/nt/avl, so it can be used as a drop-in alternative to an AVL tree.

Repository can be found at jeronimoalbi/gnome, as part of jeronimoalbi's Gno smart contracts monorepo.

Usage

 1package main
 2
 3import "gno.land/p/jeronimoalbi/trie"
 4
 5func main() {
 6	tree := trie.NewTree()
 7	tree.Set("apple", 1)
 8	tree.Set("app", 2)
 9	tree.Set("banana", 3)
10
11	// Get value for app
12	v := tree.Get("app")
13	println(v)
14
15	// Iterate keys in lexicographic order: app, apple, banana.
16	tree.Iterate("", "", func(key string, value any) bool {
17		println(key, value)
18		return false
19	})
20}
21
22// Output:
23// 2
24// app 2
25// apple 1
26// banana 3