# `gno.land/p/moul/x/daily/trie/v0`
**Prefix tree (trie) for autocomplete** — `Insert`, `Contains`, `HasPrefix`, `Complete`, `Words`, `FromWords`, `MaxWordLen`.
Insert words, then ask for everything sharing a prefix. Children are stored in a
slice kept sorted by rune (binary search on lookup, insertion sort on add), so
completions always come back in lexicographic order and the output never depends
on insertion order — no maps anywhere, because Go/gno map iteration order is
unspecified and would make a realm's `Render` vary between calls. No clocks and
no chain imports either: same input, same output, always.
`MaxWordLen` (64) bounds a single word so insertion gas stays predictable.
```go
import "gno.land/p/moul/x/daily/trie/v0"
t := trie.FromWords([]string{"carpet", "car", "cat"})
t.Complete("car", 0) // ["car" "carpet"] — lexicographic, 0 = no cap
t.Complete("car", 1) // ["car"]
t.Contains("car") // true
t.Contains("ca") // false — a prefix is not a word until inserted
t.HasPrefix("ca") // true
t.Words() // ["car" "carpet" "cat"]
```
`Complete` returns an empty (never nil) slice for an unknown prefix, so callers
can range over the result without a nil check. The empty prefix lists the whole
trie, which makes it usable as a plain sorted listing too.
**Live demo:** [`r/moul/x/daily/triedemo`](https://github.com/moul/gno-contracts/tree/main/r/moul/x/daily/triedemo/v0)
· render it at [`/r/moul/x/daily/triedemo/v0`](https://gno.land/r/moul/x/daily/triedemo/v0).
<!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) -->
---
Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
> 🧪 **Highly experimental — potentially vibe-coded.** Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md).
<!-- END GNOCONTRACTS FOOTER -->
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.