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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/trie

Directory · 5 Files
README.md Open

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