Transaction

18AF4B9C359F2B…38C2080E89D0

Block 26,374 · index 0 · indexed

Summary

Hash
18AF4B9C359F2B2EFBDB172BE9FAE5C0EB9F168847BD9AE1ABBA38C2080E89D0
Block
26,374
Size
4740 bytes
Gas used
9,601,700 / 11,522,100
Fee
1000000ugnot
Memo
gnopublish
Status
success

Messages

Arguments · 9

  1. #1multisetdemo
  2. #2README.md
  3. #3# `gno.land/r/moul/x/daily/multisetdemo/v0` **Live demo of [`p/moul/x/daily/multiset`](https://github.com/moul/gno-contracts/tree/main/p/moul/x/daily/multiset/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/multisetdemo/v0`](https://gno.land/r/moul/x/daily/multisetdemo/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/multisetdemo/v0 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/multisetdemo/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. #4gnomod.toml
  5. #5module = "gno.land/r/moul/x/daily/multisetdemo/v0" gno = "0.9"
  6. #6multisetdemo.gno
  7. #7// Package multisetdemo is a small gnoweb demo of the bag / frequency counter // provided by the [p/moul/x/daily/multiset](/p/moul/x/daily/multiset/v0) // library: word frequencies, ranking, and multiset algebra. // // It contains no counting logic of its own. Stateless, so Render is // deterministic — which is precisely what the library is for. package multisetdemo import ( "strconv" "strings" "gno.land/p/moul/x/daily/multiset/v0" ) const sample = "the quick brown fox jumps over the lazy dog the fox barks and the dog barks" // Render renders the demo for gnoweb. func Render(path string) string { var b strings.Builder b.WriteString("# Multiset\n\n") b.WriteString("A bag that counts duplicates, demoing the ") b.WriteString("[`p/moul/x/daily/multiset`](/p/moul/x/daily/multiset/v0) library.\n\n") m := multiset.FromSlice(strings.Split(sample, " ")) b.WriteString("## Word frequencies\n\n") b.WriteString("> " + sample + "\n\n") b.WriteString("`" + strconv.Itoa(m.Total()) + "` words, `") b.WriteString(strconv.Itoa(m.Distinct()) + "` distinct.\n\n") b.WriteString("## `MostCommon(5)`\n\n") b.WriteString("| rank | word | count |\n|---|---|---|\n") for i, e := range m.MostCommon(5) { b.WriteString("| " + strconv.Itoa(i+1) + " | `" + e.Elem + "` | " + strconv.Itoa(e.Count) + " |\n") } b.WriteString("\nNote the ties. `barks`, `dog` and `fox` all occur twice and are ") b.WriteString("ranked **alphabetically** — the order is count descending, then ") b.WriteString("element ascending. That second key is not decoration: without it the ") b.WriteString("ranking would fall back on map iteration order, which gno leaves ") b.WriteString("unspecified, and two nodes could render different tables.\n\n") b.WriteString("## Algebra\n\n") a := multiset.FromSlice([]string{"x", "x", "x", "y"}) c := multiset.FromSlice([]string{"x", "x", "z"}) b.WriteString("With `A = {x:3, y:1}` and `B = {x:2, z:1}`:\n\n") b.WriteString("| op | meaning | result |\n|---|---|---|\n") b.WriteString("| `Union` | max of each count | " + brief(a.Union(c)) + " |\n") b.WriteString("| `Intersect` | min, common only | " + brief(a.Intersect(c)) + " |\n") b.WriteString("| `Sum` | counts added | " + brief(a.Sum(c)) + " |\n") b.WriteString("\n## Removal\n\n") d := multiset.FromSlice([]string{"a", "a", "a"}) b.WriteString("Starting from " + brief(d) + ":\n\n") d.Remove("a") b.WriteString("- after `Remove(\"a\")` → " + brief(d) + "\n") d.RemoveN("a", 100) b.WriteString("- after `RemoveN(\"a\", 100)` → " + brief(d) + " — over-removing clears the element instead of going negative\n") return b.String() } func brief(m *multiset.MultiSet) string { if m.IsEmpty() { return "`{}`" } parts := []string{} for _, e := range m.Elements() { parts = append(parts, e+":"+strconv.Itoa(m.Count(e))) } return "`{" + strings.Join(parts, ", ") + "}`" }
  8. #8/gno.MemPackageType
  9. #9 MPUserProd

Result log

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

← Back to block 26,374