Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/daily/rle/v0

Directory · 4 Files
README.md Open

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

Run-length encoding — Encode, Decode, Ratio, MaxLen.

Runs of a repeated byte collapse to <count><char>, counts in decimal: "aaabbc" → "3a2b1c".

1import "gno.land/p/moul/x/daily/rle/v0"
2
3rle.Encode("aaabbc")   // "3a2b1c", nil
4rle.Decode("3a2b1c")   // "aaabbc", nil
5rle.Ratio("abcdef", "1a1b1c1d1e1f")  // 200 — bigger than the input!

Every run carries a count, including runs of one. A uniform grammar is cheaper to decode and impossible to get subtly wrong, at the cost of expanding data that has no runs. That trade is deliberate and visible: Ratio returns over 100 when the "compression" grew the data, because RLE only wins on runny input and pretending otherwise would be dishonest.

Digits are rejected by Encode — in the output they would be indistinguishable from a run count, so a round-trip would silently return the wrong string. Better to refuse.

Decode bounds the expanded size too, not just its input: "999999x" is seven bytes that would otherwise become a megabyte.

Live demo: r/moul/x/daily/rledemo · render it at /r/moul/x/daily/rledemo/v0.


Part of 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.