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[] Compress(byte[] Data)
 {
     byte[] bw  = BurrowsWheelerTransform.Transform(Data);
     byte[] mtf = MoveToFrontCoding.Encode(bw);
     byte[] hf  = HuffmanCoding.Encode(mtf);
     return(hf);
 }
Beispiel #3
0
        public void TestEncode()
        {
            byte[] output1    = HuffmanCoding.Encode(DECODED1);
            byte[] expoutput1 = BitStringToByteArray(ENCODED1);
            CollectionAssert.AreEqual(expoutput1, output1);

            byte[] output2    = HuffmanCoding.Encode(DECODED2);
            byte[] expoutput2 = BitStringToByteArray(ENCODED2);
            CollectionAssert.AreEqual(expoutput2, output2);
        }