Pure package detail
toposort
gno.land/p/moul/x/daily/toposort/v1
Indexed deployment identity with independently loaded latest RPC source. Functions and Render are realm-only RPC capabilities.
Indexed deployment
Identity
- Package path
- gno.land/p/moul/x/daily/toposort/v1
- Block
- 29159
- Deployed (UTC)
- Transaction
- gPcExbt6EbxbilSzuLugMNj9R1N6R6Uth/m5kJE5crA=
Latest RPC state
Source
# `gno.land/p/moul/x/daily/toposort/v1`
**Topological sort of a dependency graph** — `New`, `FromPairs`, `Add`,
`DependOn`, `Sort`, `CycleNodes`, `Nodes`, `DependenciesOf`, `String`.
Orders a graph so every node comes after everything it depends on — the "install
these packages in a safe order" problem — using Kahn's algorithm.
```go
import "gno.land/p/moul/x/daily/toposort/v1"
g := toposort.FromPairs([][2]string{
{"realm", "ui"}, {"ui", "markdown"}, {"markdown", "strings"},
})
order, err := g.Sort() // ["strings" "markdown" "ui" "realm"], nil
```
**Deterministic by construction.** Among nodes that become ready at the same
time, the lexicographically smallest is always emitted first, so a given graph
has exactly one possible answer regardless of insertion order. Adjacency is kept
in sorted slices and no map is ever *iterated* — Go/gno map iteration order is
unspecified, and a realm whose `Render` reshuffled between identical calls would
be a bug.
A cycle is **reported, not hidden**: `Sort` returns `ErrCycle` along with the
partial order it managed, and `CycleNodes` names the nodes still stuck so a
caller can say exactly which dependencies are tangled.
Edge cases: a self-dependency is ignored as a trivial cycle but the node stays
in the graph; duplicate edges collapse; empty names are rejected; `Nodes` and
`DependenciesOf` return copies, so a caller cannot mutate the graph through them.
**Live demo:** [`r/moul/x/daily/toposortdemo`](https://github.com/moul/gno-contracts/tree/main/r/moul/x/daily/toposortdemo/v1)
· render it at [`/r/moul/x/daily/toposortdemo/v1`](https://gno.land/r/moul/x/daily/toposortdemo/v1).
<!-- 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 -->
The verified vm/qfuncs operation accepts realm paths only.
Pure packages expose source files but do not have Realm Render.