Beispiel #1
0
        public void Run(string[] args)
        {
            string inputFileName   = "../../Data/Project02/" + args[0];
            string encodedFileName = "../../Data/Project02/" + args[1];
            string decodedFileName = "../../Data/Project02/" + args[2];

            // load input data
            Vector <char> inputData = null;

            DataSerializer <char> .LoadVectorFromTextFile(inputFileName, ref inputData);

            // create a coder
            HuffmanCoding coder = new HuffmanCoding();

            // encode input data
            Vector <string> encodedData = null;

            encodedData = coder.Encode(inputData);

            // write the encoded data to file
            DataSerializer <string> .SaveVectorToTextFile(encodedFileName, encodedData);

            // reload the encoded data from file
            DataSerializer <string> .LoadVectorFromTextFile(encodedFileName, ref encodedData);

            // decode the encoded data
            Vector <char> decodedData = null;

            decodedData = coder.Decode(encodedData);

            // write the decoded data to file
            DataSerializer <char> .SaveVectorToTextFile(decodedFileName, decodedData);

            // reload the decodedData from file
            DataSerializer <char> .LoadVectorFromTextFile(decodedFileName, ref decodedData);

            // validating the coding result, i.e. checking whether inputData = decodedData
            if (inputData.Count != decodedData.Count)
            {
                Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!");
            }
            else
            {
                int i;
                for (i = 0; i < inputData.Count; i++)
                {
                    if (!inputData[i].Equals(decodedData[i]))
                    {
                        Console.WriteLine("Input data is not identical to decoded data -- Coding method does not work accurately!");
                        break;
                    }
                }
                if (i == inputData.Count)
                {
                    Console.WriteLine("Coding method works accurately!");
                }
            }

            Console.Read();
        }
 public static byte[] Decompress(byte[] data)
 {
     byte[] dhf  = HuffmanCoding.Decode(data);
     byte[] imtf = MoveToFrontCoding.Decode(dhf);
     byte[] ibw  = BurrowsWheelerTransform.InverseTransform(imtf);
     return(ibw);
 }
Beispiel #3
0
        public void TestDecode()
        {
            byte[] encoded1 = BitStringToByteArray(ENCODED1);
            byte[] decoded1 = HuffmanCoding.Decode(encoded1);
            CollectionAssert.AreEqual(DECODED1, decoded1);

            byte[] encoded2 = BitStringToByteArray(ENCODED2);
            byte[] decoded2 = HuffmanCoding.Decode(encoded2);
            CollectionAssert.AreEqual(DECODED2, decoded2);
        }