PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

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/r/moul/x/daily/bidimapdemo/v0

Realm
Open in gnoweb ↗

Overview

Kind
Realm (renderable)
Name
v0
Namespace
moul / x / daily / bidimapdemo
Files
3 (README)(gnomod.toml)
Exported functions
1
Module
gno.land/r/moul/x/daily/bidimapdemo/v0
gno
0.9

Files (3)

  • README.mdmarkdown
  • gnomod.tomltoml
  • bidimapdemo.gnogno

Select a file to view its exact on-chain source. Sorted README → gnomod → sources → tests.

Functions

  • Render(path string) string

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

Rendered

RenderedRawgnoweb ↗
# Bidirectional Map

Unique in both directions, demoing the [`p/moul/x/daily/bidimap`](/p/moul/x/daily/bidimap/v0) library.

## Roles

| person | role |
|---|---|
| `alice` | `admin` |
| `bob` | `auditor` |
| `carol` | `treasurer` |

## Both directions are O(1)

- `Get("bob")` → `auditor`
- `GetKey("treasurer")` → `carol` — the reverse index, not a scan

## Displacing a binding

Both sides are unique, so giving `alice` the `auditor` role cannot simply be written — `bob` already holds it, and `alice` already holds `admin`. `Put` **replaces**, and reports what it displaced:

| displaced key | displaced value |
|---|---|
| `alice` | `admin` |
| `bob` | `auditor` |

| person | role |
|---|---|
| `alice` | `auditor` |
| `carol` | `treasurer` |

`bob` is now unassigned and the `admin` role is vacant — one call, both indexes still agreeing.

## Refusing instead

`PutUnique` makes the other choice: it declines rather than displace.

- `PutUnique("dave", "auditor")` → `false` — the role is taken
- `PutUnique("dave", "secretary")` → `true` — both sides free

| person | role |
|---|---|
| `alice` | `auditor` |
| `carol` | `treasurer` |
| `dave` | `secretary` |

> Keys come back **sorted**, never in map order: gno map iteration order is unspecified, and a page built from one can differ between nodes — a consensus bug, not a cosmetic one.

vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.