PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/moul/x/daily/multiset/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
moul / x / daily / multiset
Files
3 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/moul/x/daily/multiset/v0
gno
0.9

Files (3)

  • README.mdmarkdown
  • gnomod.tomltoml
  • multiset.gnogno
README.mdPreviewRaw
# `gno.land/p/moul/x/daily/multiset/v0`

**Bag / frequency counter** — `New`, `FromSlice`, `Add`, `AddN`, `Remove`,
`RemoveN`, `RemoveAll`, `Count`, `MostCommon`, `Union`, `Intersect`, `Sum`,
`Elements`, `Expand`, `Clone`, `MaxDistinct`.

```go
import "gno.land/p/moul/x/daily/multiset/v0"

m := multiset.FromSlice([]string{"a", "a", "a", "b", "b", "c"})
m.Count("a")        // 3
m.MostCommon(2)     // [{a 3} {b 2}]
m.Total()           // 6 occurrences
m.Distinct()        // 3 elements
```

The STL `multiset` and Python's `collections.Counter` in one type.

**`MostCommon` has a total order:** count descending, then element ascending.
Sorting by count alone would leave ties in whatever order the backing map
yielded — unspecified in gno, and enough to make two nodes render different
tables from identical state. The tiebreak is not decoration.

Semantics worth knowing, each with a test:

- **A count reaching zero removes the element**, rather than leaving a
  zero-count ghost that `Distinct` would still count.
- **`RemoveN` clamps**: removing more than are present clears the element
  instead of going negative.
- `Union` takes the **max** of each count, `Intersect` the **min** (common
  elements only), `Sum` adds them.

`MaxDistinct` (4096) bounds the number of *distinct* elements; counts themselves
are unbounded, so a full set still accepts more occurrences of what it holds.

**Live demo:** [`r/moul/x/daily/multisetdemo`](https://github.com/moul/gno-contracts/tree/main/r/moul/x/daily/multisetdemo/v0)
· render it at [`/r/moul/x/daily/multisetdemo/v0`](https://gno.land/r/moul/x/daily/multisetdemo/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 -->

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.