Exemple #1
0
        }//end DecompressFile method

        //
        //COMPRESSION METHODS
        //


        //
        //
        //Compression #1
        //This counts the character frequency of the input file and puts that data into an array. It then returns this array of character frequency objects.
        static Array BuildCharArray(string inputFilePath)
        {
            CharacterFrequency[] cfArray  = new CharacterFrequency[256];
            FileStream           fileRead = new FileStream(inputFilePath, FileMode.Open);

            //This fills each element in the CharacterFrequency array with its respective ASCII value. The index of the element is the ASCII value.
            for (int i = 0; i < cfArray.Length; ++i)
            {
                //Converts the array element to its respective ASCII character value.
                cfArray[i] = new CharacterFrequency(Convert.ToChar(i));
            }

            //for loop iterates once per character in the receieved file.
            long fileLength = fileRead.Length;

            for (int i = 0; i < fileLength; ++i)
            {
                //Creates a temporary CharacterFrequency object that stores the next read byte.
                CharacterFrequency tempCF = new CharacterFrequency(Convert.ToChar(fileRead.ReadByte()));

                //Creates a temporary int that stores the ASCII value found in the tempCF CharacterFrequency object.
                int tempASCII = Convert.ToInt32(tempCF.GetCh());

                //Searches the array that holds CharacterFrequency objects. The index for the search is the ASCII value for the character in the temporary CharacterFrequency object.
                if (cfArray[tempASCII].Equals(tempCF) == true)
                {
                    //If the CharacterFrequency object is found in the CharacterFrequency array, the object is incremented.
                    cfArray[tempASCII].Increment();
                }
            }

            fileRead.Close();
            return(cfArray);
        }//end BuildCharArray method
Exemple #2
0
        }//end Increment method

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is CharacterFrequency))
            {
                return(false);
            }

            CharacterFrequency cf = obj as CharacterFrequency;

            return(this.GetCh() == cf.GetCh());
        }//end Equals method