Transaction

0F28BF19E4D582…F08763DEFB11

Block 26,067 · index 0 · indexed

Summary

Hash
0F28BF19E4D582B351116C7852888DBFC95C106A4DBEB25FBB3CF08763DEFB11
Block
26,067
Size
4937 bytes
Gas used
9,773,998 / 11,728,857
Fee
1000000ugnot
Memo
gnopublish
Status
success

Messages

Arguments · 9

  1. #1flatmapdemo
  2. #2README.md
  3. #3# `gno.land/r/moul/x/daily/flatmapdemo/v0` **Live demo of [`p/moul/x/daily/flatmap`](https://github.com/moul/gno-contracts/tree/main/p/moul/x/daily/flatmap/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/flatmapdemo/v0`](https://gno.land/r/moul/x/daily/flatmapdemo/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/flatmapdemo/v0 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/flatmapdemo/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. #4flatmapdemo.gno
  5. #5// Package flatmapdemo is a small gnoweb demo of the sorted-vector map provided // by the [p/moul/x/daily/flatmap](/p/moul/x/daily/flatmap/v0) library: sorted // storage, indexed access and range queries. // // It contains no map logic of its own. Stateless, so Render is deterministic — // which is precisely what the library is for. package flatmapdemo import ( "strconv" "strings" "gno.land/p/moul/x/daily/flatmap/v0" ) // Render renders the demo for gnoweb. func Render(path string) string { var b strings.Builder b.WriteString("# Flat Map\n\n") b.WriteString("A map backed by sorted slices, demoing the ") b.WriteString("[`p/moul/x/daily/flatmap`](/p/moul/x/daily/flatmap/v0) library.\n\n") f := flatmap.New() inserted := []string{"delta", "alpha", "echo", "bravo", "charlie"} for i, k := range inserted { f.Set(k, strconv.Itoa(i+1)) } b.WriteString("## Sorted by construction\n\n") b.WriteString("Inserted as `" + strings.Join(inserted, ", ") + "` — stored sorted:\n\n") b.WriteString(table(f)) b.WriteString("\nNo sort on read, and no dependence on map iteration order — which ") b.WriteString("gno leaves unspecified, and which would let two nodes render different ") b.WriteString("pages from the same state.\n\n") b.WriteString("## Indexed access\n\n") b.WriteString("Sorted storage gives positional lookup that a hash map cannot:\n\n") for _, i := range []int{0, 2, 4} { k, v, _ := f.At(i) b.WriteString("- `At(" + strconv.Itoa(i) + ")` → `" + k + "` = `" + v + "`\n") } b.WriteString("\n## Range queries\n\n") b.WriteString("Two binary searches and a walk — `lo` inclusive, `hi` exclusive:\n\n") b.WriteString("| range | keys |\n|---|---|\n") b.WriteString("| `[\"bravo\", \"delta\")` | " + rng(f, "bravo", "delta") + " |\n") b.WriteString("| `[\"charlie\", ∞)` | " + rng(f, "charlie", "") + " |\n") b.WriteString("| `[\"b\", \"d\")` | " + rng(f, "b", "d") + " |\n") b.WriteString("\nThe last one asks for bounds that are not keys at all — the search ") b.WriteString("still lands in the right place.\n\n") b.WriteString("## The trade\n\n") b.WriteString("| operation | cost |\n|---|---|\n") b.WriteString("| `Get` | O(log n) binary search over contiguous memory |\n") b.WriteString("| iteration | O(n), already ordered, nothing to sort |\n") b.WriteString("| `Set` in the middle | **O(n)** — the tail shifts |\n") b.WriteString("| `Set` at the end | O(1) amortised — the fast path |\n") b.WriteString("\nCheap reads and cheap ordered iteration, paid for at write time.\n") return b.String() } func table(f *flatmap.FlatMap) string { var b strings.Builder b.WriteString("| # | key | value |\n|---|---|---|\n") i := 0 f.Iterate(func(k, v string) bool { b.WriteString("| " + strconv.Itoa(i) + " | `" + k + "` | `" + v + "` |\n") i++ return false }) return b.String() } func rng(f *flatmap.FlatMap, lo, hi string) string { var out []string f.Range(lo, hi, func(k, v string) bool { out = append(out, "`"+k+"`") return false }) if len(out) == 0 { return "_none_" } return strings.Join(out, ", ") }
  6. #6gnomod.toml
  7. #7module = "gno.land/r/moul/x/daily/flatmapdemo/v0" gno = "0.9"
  8. #8/gno.MemPackageType
  9. #9 MPUserProd

Result log

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

← Back to block 26,067