Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

v0 source realm

Package huffmandemo is a small gnoweb demo of the canonical Huffman codec provided by the [p/moul/x/daily/huffman](/p...

Readme View source

Huffman coding

Shows the code table for abracadabra, the packed bit stream it produces, what the skew is worth across four inputs, and the two cases that break a naive implementation.

/r/moul/x/daily/huffmandemo/v0              → the worked example and the ratios
/r/moul/x/daily/huffmandemo/v0:mississippi  → encode your own text

Demo of the p/moul/x/daily/huffman library, no codec logic lives here. Stateless, so Render is deterministic: every figure comes from the fixed strings at the top of the file and never from chain state, which is what lets the pinned example test assert the whole page.

The comparison table is the honest part. A flat alphabet of eight bytes still shows a 62% saving, because the floor is the size of the alphabet and not the cleverness of the code: three bits per symbol is what a fixed-width code would have spent too. Everything past that floor is bought with skew, which is why the last row, thirty a and three other bytes, reaches 85%.

Text taken from the path is attacker-controlled markdown, so it goes through ui.Inline and ui.Cell before it is rendered back. A symbol is shown by its byte: anything outside printable ASCII renders as hex, because converting a byte above 127 with string(b) would print a character the code does not stand for.

Built for gno 0.9.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

On mainnet: deployment status transactions unique callers deployed revision

Dependency graph:

gno.land/r/moul/x/daily/huffmandemo/v0 dependency graph

🧪 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.

Overview

Package huffmandemo is a small gnoweb demo of the canonical Huffman codec provided by the p/moul/x/daily/huffman(/p/moul/x/daily/huffman/v0) library: the code table for a worked example, what the packed stream looks like, what the skew is worth, and the two inputs that break a naive implementation.

It contains no codec logic of its own. Stateless, so Render is deterministic: every figure below is computed from the fixed strings at the top of this file, never from chain state, which is what lets an example test pin the page.

Functions 1

func Render

1func Render(path string) string
source

Render renders the demo for gnoweb.

Example
1Render("") / Render("/") -> the worked example, the ratios, the edge cases
2Render("/<text>")        -> encode that text and show its table

Dependencies

Source Files 4