Grammar-Based Compression, Explained by Building One

Re-Pair is the most readable compression idea I know: replace the most frequent pair, record the rule, repeat. Building it in Rust made compression stop being magic.