Example #1
0
        public string Decode(BitArray code, out int codeLength)
        {
            var index  = 0;
            var length = BitArrayConverter.ConvertToInt(code, ref index, 32);
            var dict   = FrequencyDictionaryCoder.GetDictionary(code, ref index);

            codeLength = code.Length - index;
            return(TextDecode(code, index, dict, length));
        }
Example #2
0
        private List <Pair <char, int> > BitArrayToListOfPairs(BitArray code)
        {
            var res   = new List <Pair <char, int> >();
            var index = 0;

            while (index < code.Length)
            {
                var symbol = BitArrayConverter.ConvertToChar(code, ref index);
                var number = BitArrayConverter.ConvertToInt(code, ref index, LengthOfNumber);
                res.Add(new Pair <char, int>(symbol, number));
            }

            return(res);
        }
        public static Dictionary <char, int> GetDictionary(BitArray code, ref int index)
        {
            var res = new Dictionary <char, int>();
            var cnt = BitArrayConverter.ConvertToInt(code, ref index, 8);

            for (var _ = 0; _ < cnt; _++)
            {
                var symbol  = BitArrayConverter.ConvertToInt(code, ref index, 16);
                var newCode = BitArrayConverter.ConvertToInt(code, ref index, 32);

                res.Add((char)symbol, newCode);
            }

            return(res);
        }
Example #4
0
        public static Dictionary <BitArray, char> GetDictionary(BitArray code, ref int index)
        {
            var res = new Dictionary <BitArray, char>(new BitArrayComparer());
            var cnt = BitArrayConverter.ConvertToInt(code, ref index, 8);

            for (var _ = 0; _ < cnt; _++)
            {
                var symbol  = BitArrayConverter.ConvertToInt(code, ref index, 16);
                var length  = BitArrayConverter.ConvertToInt(code, ref index, 5);
                var newCode = new BitArray(length);

                for (var i = 0; i < length; i++)
                {
                    newCode[i] = code[index];
                    index++;
                }

                res.Add(newCode, (char)symbol);
            }

            return(res);
        }