The Huffman code is the typical classic among compression codes, as this is an algorithm for lossless data compression. The C# code has a simple structure and fulfills the very fast derivation of the Huffman code, as well as the decoding. It's worth taking a look.
https://github.com/michelenatale/Compress/tree/main/HuffmanCoding