public static byte[] Encode(IEnumerable <byte> data, out Dictionary <BitsWithLength, byte> decodeTable,
                                    out long bitsCount)
        {
            var dArr       = data.ToArray();
            var frequences = CalcFrequences(dArr);

            var root = BuildHuffmanTree(frequences);

            var encodeTable = new BitsWithLength[byte.MaxValue + 1];

            FillEncodeTable(root, encodeTable);

            var bitsBuffer = new BitsBuffer();

            foreach (var b in dArr)
            {
                bitsBuffer.Add(encodeTable[b]);
            }

            decodeTable = CreateDecodeTable(encodeTable);

            return(bitsBuffer.ToArray(out bitsCount));
        }