Пример #1
0
 private void leeHashEstatica(string directorio)
 {
     try
     {
         HashEstatica hash;
         hash = new HashEstatica(this.nombre, this.dirIndice, this.longitud, -1, this.tipo.Equals('C'));
         using (reader = new BinaryReader(new FileStream(directorio, FileMode.Open)))//Abre el archivo con el BinaryWriter
         {
             reader.BaseStream.Position = this.dirIndice;
             for (int i = 0; i < hash.Direcciones.Length; i++)
             {
                 hash.Direcciones[i] = reader.ReadInt64();
             }
         }
         for (int i = 0; i < hash.Direcciones.Length; i++)
         {
             this.LeeApuntadoresHash(directorio, i, hash);
         }
         this.indices.Add(hash);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Пример #2
0
 private void grabaApuntadoresHash(string directorio, HashEstatica hash, long dir, int i)
 {
     try
     {
         using (writer = new BinaryWriter(new FileStream(directorio, FileMode.Open))) //Abre el archivo con el BinaryWriter
         {
             this.writer.Seek((int)dir, SeekOrigin.Current);                          //Posiciona el grabado del archivo en la dirección actual
             for (int j = 0; j < hash.Longitud; j++)
             {
                 if (this.tipo.Equals('C'))
                 {
                     writer.Write(hash.Llaves[i, j].ToCharArray());
                 }
                 else if (this.tipo.Equals('E'))
                 {
                     writer.Write(Int32.Parse(hash.Llaves[i, j]));
                 }
                 else if (this.tipo.Equals('D'))
                 {
                     writer.Write(float.Parse(hash.Llaves[i, j]));
                 }
                 writer.Write(hash.Apuntadores[i, j]);
             }
             writer.Write(((long)-1));
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Пример #3
0
        public void altaHash(string llave, long direccion, string directorio)
        {
            bool band;

            band = false;
            band = this.tipo.Equals('C');
            if (this.dirIndice == -1)
            {
                HashEstatica hash;
                hash = new HashEstatica(this.nombre, this.dirIndice, this.longitud, -1, band);
                this.indices.Add(hash);
                this.dirIndice = MetodosAuxiliares.ultimaDireccionDeArchivo(directorio);
                this.grabaDireccionesHash(directorio, hash);
                for (int i = 0; i < hash.Direcciones.Length; i++)
                {
                    hash.Direcciones[i] = MetodosAuxiliares.ultimaDireccionDeArchivo(directorio);
                    this.grabaApuntadoresHash(directorio, hash, hash.Direcciones[i], i);
                }
                this.grabaDireccionesHash(directorio, hash);
            }
            int idx;

            idx = ((HashEstatica)this.indices.First()).alta(band, MetodosAuxiliares.truncaCadena(llave).ToCharArray(), this.longitud, direccion);
            this.grabaApuntadoresHash(directorio, ((HashEstatica)this.indices.First()), ((HashEstatica)this.indices.First()).Direcciones[idx], idx);
        }
Пример #4
0
 private void grabaDireccionesHash(string directorio, HashEstatica hash)
 {
     try
     {
         using (writer = new BinaryWriter(new FileStream(directorio, FileMode.Open))) //Abre el archivo con el BinaryWriter
         {
             this.writer.Seek((int)this.dirIndice, SeekOrigin.Current);               //Posiciona el grabado del archivo en la dirección actual
             for (int i = 0; i < hash.Direcciones.Length; i++)
             {
                 writer.Write(hash.Direcciones[i]);
             }
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Пример #5
0
 private void LeeApuntadoresHash(string directorio, int i, HashEstatica hash)
 {
     try
     {
         bool band;
         band = this.tipo.Equals('C');
         using (reader = new BinaryReader(new FileStream(directorio, FileMode.Open)))
         {
             reader.BaseStream.Position = hash.Direcciones[i];
             for (int j = 0; j < hash.Longitud; j++)
             {
                 if (band)
                 {
                     hash.Llaves[i, j] = new string(reader.ReadChars(this.longitud));
                 }
                 else
                 {
                     if (this.tipo.Equals('E'))
                     {
                         hash.Llaves[i, j] = reader.ReadInt32().ToString();
                     }
                     else
                     {
                         hash.Llaves[i, j] = reader.ReadSingle().ToString();
                     }
                 }
                 hash.Apuntadores[i, j] = reader.ReadInt64();
             }
             reader.ReadInt64();
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }