NodeComponents NodeAssembler(NodeComponents lowNode, NodeComponents maxNode)
        {
            var father        = new NodeComponents();
            var infoNewFather = new initialReadComponents();

            father.CharacterData = infoNewFather;
            father.LeftSon       = lowNode;
            father.RigthSon      = maxNode;
            father.CharacterData.probabilidad = lowNode.CharacterData.probabilidad + maxNode.CharacterData.probabilidad;
            return(father);
        }
Beispiel #2
0
        public string generateCharactersList(HttpPostedFileBase file)
        {
            var bufferLength = file.ContentLength;

            var amountOfCharacters = 0;
            List <initialReadComponents> charactersList = new List <initialReadComponents>();
            Stream stream = file.InputStream;

            //se hace una copia del archivo
            var ms = new MemoryStream();

            file.InputStream.CopyTo(ms);
            file.InputStream.Position = ms.Position = 0;

            using (var reader = new BinaryReader(stream))
            {
                amountOfCharacters = Convert.ToInt32(reader.BaseStream.Length);
                var byteBurffer = new byte[bufferLength];
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    byteBurffer = reader.ReadBytes(bufferLength);
                    for (int i = 0; i < byteBurffer.Length; i++)
                    {
                        var characterForList = new initialReadComponents();
                        characterForList = charactersList.Find(x => x.caracter == byteBurffer[i]);
                        if (characterForList == null)
                        {
                            characterForList            = new initialReadComponents();
                            characterForList.caracter   = byteBurffer[i];
                            characterForList.frecuencia = 1;
                            charactersList.Add(characterForList);
                        }
                        else
                        {
                            characterForList.frecuencia++;
                        }
                    }
                }
            }

            for (int i = 0; i < charactersList.Count; i++)
            {
                charactersList[i].probabilidad = Convert.ToDouble(charactersList[i].frecuencia) / Convert.ToDouble(amountOfCharacters);
            }
            return(ComprimirArchivo(charactersList, ms, file.FileName, bufferLength));
        }