Transaction

2A753B772D2C9C…A5F2288F928D

Block 25,992 · index 0 · indexed

Summary

Hash
2A753B772D2C9CD58BCF2E1994B8733D9D6E00968E93E82F60C4A5F2288F928D
Block
25,992
Size
4636 bytes
Gas used
9,389,621 / 11,267,605
Fee
1000000ugnot
Memo
gnopublish
Status
success

Messages

Arguments · 9

  1. #1bidimapdemo
  2. #2README.md
  3. #3# `gno.land/r/moul/x/daily/bidimapdemo/v0` **Live demo of [`p/moul/x/daily/bidimap`](https://github.com/moul/gno-contracts/tree/main/p/moul/x/daily/bidimap/v0).** A thin, stateless realm: it holds no state of its own and contains none of the library's logic — `Render` just exercises the package and shows the result. Because it is stateless, the rendered page is identical on every call and on every node. Render it at [`/r/moul/x/daily/bidimapdemo/v0`](https://gno.land/r/moul/x/daily/bidimapdemo/v0). The library README explains the design and the trade-offs; this realm is the worked example. <!-- 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. **Dependency graph:** ![gno.land/r/moul/x/daily/bidimapdemo/v0 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/bidimapdemo/v0/deps.png) > 🧪 **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 -->
  4. #4bidimapdemo.gno
  5. #5// Package bidimapdemo is a small gnoweb demo of the bidirectional map provided // by the [p/moul/x/daily/bidimap](/p/moul/x/daily/bidimap/v0) library: it shows // the reverse lookup and what happens when a binding is displaced. // // It contains no map logic of its own. Stateless, so Render is deterministic — // which is precisely what the library is for. package bidimapdemo import ( "strconv" "strings" "gno.land/p/moul/x/daily/bidimap/v0" ) // Render renders the demo for gnoweb. func Render(path string) string { var b strings.Builder b.WriteString("# Bidirectional Map\n\n") b.WriteString("Unique in both directions, demoing the ") b.WriteString("[`p/moul/x/daily/bidimap`](/p/moul/x/daily/bidimap/v0) library.\n\n") m := bidimap.New() m.Put("alice", "admin") m.Put("bob", "auditor") m.Put("carol", "treasurer") b.WriteString("## Roles\n\n") b.WriteString(table(m)) b.WriteString("\n## Both directions are O(1)\n\n") v, _ := m.Get("bob") k, _ := m.GetKey("treasurer") b.WriteString("- `Get(\"bob\")` → `" + v + "`\n") b.WriteString("- `GetKey(\"treasurer\")` → `" + k + "` — the reverse index, not a scan\n\n") b.WriteString("## Displacing a binding\n\n") b.WriteString("Both sides are unique, so giving `alice` the `auditor` role cannot ") b.WriteString("simply be written — `bob` already holds it, and `alice` already holds ") b.WriteString("`admin`. `Put` **replaces**, and reports what it displaced:\n\n") evicted, _ := m.Put("alice", "auditor") b.WriteString("| displaced key | displaced value |\n|---|---|\n") for _, p := range evicted { b.WriteString("| `" + p[0] + "` | `" + p[1] + "` |\n") } b.WriteString("\n" + table(m)) b.WriteString("\n`bob` is now unassigned and the `admin` role is vacant — one call, ") b.WriteString("both indexes still agreeing.\n\n") b.WriteString("## Refusing instead\n\n") b.WriteString("`PutUnique` makes the other choice: it declines rather than displace.\n\n") ok := m.PutUnique("dave", "auditor") b.WriteString("- `PutUnique(\"dave\", \"auditor\")` → `" + strconv.FormatBool(ok) + "` — the role is taken\n") ok = m.PutUnique("dave", "secretary") b.WriteString("- `PutUnique(\"dave\", \"secretary\")` → `" + strconv.FormatBool(ok) + "` — both sides free\n\n") b.WriteString(table(m)) b.WriteString("\n> Keys come back **sorted**, never in map order: gno map iteration ") b.WriteString("order is unspecified, and a page built from one can differ between ") b.WriteString("nodes — a consensus bug, not a cosmetic one.\n") return b.String() } func table(m *bidimap.BiMap) string { var b strings.Builder b.WriteString("| person | role |\n|---|---|\n") m.Iterate(func(k, v string) bool { b.WriteString("| `" + k + "` | `" + v + "` |\n") return false }) return b.String() }
  6. #6gnomod.toml
  7. #7module = "gno.land/r/moul/x/daily/bidimapdemo/v0" gno = "0.9"
  8. #8/gno.MemPackageType
  9. #9 MPUserProd

Result log

msg:0,success:true,log:,events:[]

← Back to block 25,992