コード例 #1
0
ファイル: Huffman.cs プロジェクト: feroliv4z/ProyectoEDII
        public Dictionary <char, charCount> LecturaArchivoCompresion(Dictionary <char, charCount> diccionario, string ArchivoLeido, int bufferLengt, ref List <byte> ListaByte)
        {
            //el siguiente if permite seleccionar un archivo en específico
            using (var stream = new FileStream(ArchivoLeido, FileMode.Open))
            {
                //te va a devolver un numero cualquiera
                using (var reader = new BinaryReader(stream))
                {
                    var byteBuffer = new byte[bufferLengt];
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        byteBuffer = reader.ReadBytes(bufferLengt);
                        foreach (byte bit in byteBuffer)
                        {
                            charCount cantidad = new charCount();

                            if (!diccionario.ContainsKey((char)bit))
                            {
                                cantidad.cantidad = 1;
                                diccionario.Add((char)bit, cantidad);
                            }
                            else
                            {
                                diccionario[(char)bit].cantidad++;
                            }
                            ListaByte.Add(bit);
                        }
                    }
                }
            }
            return(diccionario);
        }
コード例 #2
0
 public Dictionary <char, charCount> prefixCodes(Node root, Dictionary <char, charCount> codesDictionary, string prefixCode)
 {
     if (root == null)
     {
         return(codesDictionary);
     }
     else
     {
         codesDictionary = prefixCodes(root.leftChild, codesDictionary, prefixCode + 0);
         if (root.rightChild == null && root.leftChild == null)
         {
             if (codesDictionary.ContainsKey(Convert.ToChar(root.character)))
             {
                 charCount cantidad = new charCount();
                 cantidad.codPref = prefixCode;
                 codesDictionary.Remove(Convert.ToChar(root.character));
                 codesDictionary.Add(Convert.ToChar(root.character), cantidad);
                 nodeCount++;
                 createDictionaryFile(root.character, prefixCode, codesDictionary);
             }
         }
         codesDictionary = prefixCodes(root.rightChild, codesDictionary, prefixCode + 1);
     }
     return(codesDictionary);
 }
コード例 #3
0
        public int CompareTo(object obj)
        {
            charCount compareToObj = (charCount)obj;

            return(this.cantidad.CompareTo(compareToObj.cantidad));
        }