Example #1
0
        public void altaIndiceSecundario(string llave, long direccion, string directorio)
        {
            bool band;

            band = this.tipo.Equals('C');
            Secundario secunadrio;

            if (this.dirIndice == -1)
            {
                int tam;
                tam        = MetodosAuxiliares.calculaTamIdxPrim(this.longitud);
                secunadrio = new Secundario(this.nombre, this.dirIndice, tam, this.longitud, -1, band);
                this.indices.Add(secunadrio);
                this.dirIndice = MetodosAuxiliares.ultimaDireccionDeArchivo(directorio);
                this.grabaDireccionesSecundario(directorio, secunadrio);
                for (int i = 0; i < secunadrio.Direcciones.Length; i++)
                {
                    secunadrio.Direcciones[i] = MetodosAuxiliares.ultimaDireccionDeArchivo(directorio);
                    this.grabaApuntadoresSecundario(directorio, secunadrio, secunadrio.Direcciones[i], i);
                }
            }
            int idx;

            secunadrio = ((Secundario)this.indices.First());
            idx        = secunadrio.alta(llave, direccion);
            this.grabaApuntadoresSecundario(directorio, secunadrio, secunadrio.Direcciones[idx], idx);
            this.grabaDireccionesSecundario(directorio, secunadrio);
        }
Example #2
0
 private void leeIndicePrimario(string directorio)
 {
     try
     {
         Indice indice;
         long   dirSig;
         int    largo;
         string llave;
         long   direccion;
         llave     = "-1";
         direccion = -1;
         dirSig    = this.dirIndice;
         largo     = MetodosAuxiliares.calculaTamIdxPrim(this.longitud);
         NodoIndicePrimario[] nodos;
         nodos = new NodoIndicePrimario[largo];
         NodoIndicePrimario nodo;
         while (dirSig != -1)
         {
             using (reader = new BinaryReader(new FileStream(directorio, FileMode.Open)))//Abre el archivo con el BinaryWriter
             {
                 reader.BaseStream.Seek(this.dirIndice, SeekOrigin.Current);
                 for (int i = 0; i < largo; i++)
                 {
                     if (this.tipo == 'C')
                     {
                         llave = new string(this.reader.ReadChars(this.longitud));
                     }
                     else
                     {
                         llave = this.reader.ReadInt32().ToString();
                     }
                     direccion = this.reader.ReadInt64();
                     nodo      = new NodoIndicePrimario(llave, direccion);
                     nodos[i]  = nodo;
                 }
                 indice = new Primario(this.nombre, dirSig, nodos, largo, -1);
                 this.indices.Add(indice);
                 dirSig = reader.ReadInt64();
             }
         }
         for (int i = 0; i < this.Indices.Count - 1; i++)
         {
             this.indices[i].DirSig = this.indices[i + 1].DirAct;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Example #3
0
 private void leeSecundario(string directorio)
 {
     try
     {
         Secundario secundario;
         bool       band;
         band = this.tipo.Equals('C');
         int tamaño;
         tamaño     = MetodosAuxiliares.calculaTamIdxPrim(this.longitud);
         secundario = new Secundario(this.nombre, this.dirIndice, tamaño, this.longitud, -1, band);
         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 < secundario.Direcciones.Length; i++)
             {
                 if (band)
                 {
                     secundario.Llaves[i] = new string(reader.ReadChars(this.longitud));
                 }
                 else
                 {
                     if (this.tipo.Equals('E'))
                     {
                         secundario.Llaves[i] = reader.ReadInt32().ToString();
                     }
                     else
                     {
                         secundario.Llaves[i] = reader.ReadSingle().ToString();
                     }
                 }
                 secundario.Direcciones[i] = reader.ReadInt64();
             }
             secundario.DirSig = reader.ReadInt64();
         }
         for (int i = 0; i < secundario.Direcciones.Length; i++)
         {
             this.LeeApuntadoresSecundario(directorio, i, secundario);
         }
         this.indices.Add(secundario);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Example #4
0
        public void altaIndicePrimario(string llave, long dir, string directorio)
        {
            int    longitud;
            long   dirIdx;
            Indice indice;

            dirIdx   = -1;
            longitud = MetodosAuxiliares.calculaTamIdxPrim(this.longitud);
            dirIdx   = MetodosAuxiliares.ultimaDireccionDeArchivo(directorio);
            if (this.indices.Count == 0)
            {
                indice = new Primario(this.nombre, dirIdx, longitud, -1);
                ((Primario)indice).alta(llave, dir);
                this.indices.Add(indice);
            }
            else
            {
                bool band;
                band = false;
                foreach (Indice idx in this.indices)
                {
                    if (((Primario)idx).EspacioLibre != -1)
                    {
                        ((Primario)idx).alta(llave, dir);
                        band = true;
                        break;
                    }
                }
                if (!band)
                {
                    indice = new Primario(this.nombre, dirIdx, longitud, -1);
                    ((Primario)indice).alta(llave, dir);
                    this.indices.Last().DirSig = indice.DirAct;
                    this.indices.Add(indice);
                }
            }
            this.dirIndice = this.indices.First().DirAct;
            foreach (Indice idx in this.indices)
            {
                this.grabaIndicePrimario((Primario)idx, directorio);
            }
        }
 public HashEstatica(string nombre, long dir, int longitud, long dirSig, bool esCadena) : base(nombre, dir, dirSig)//OH no las cantantes!!!
 {
     this.direcciones = new long[Constantes.valorHash];
     this.longitud = MetodosAuxiliares.calculaTamIdxPrim(longitud);
     this.llaves = new string[Constantes.valorHash, this.longitud];
     this.apuntadores = new long[Constantes.valorHash, this.longitud];
     for(int i = 0 ; i < Constantes.valorHash ; i++)
     {
         this.direcciones[i] = -1;
         for (int j = 0; j < this.longitud; j++)
         {
             this.llaves[i, j] = "-1";
             this.apuntadores[i,j] = -1;
             if (esCadena)
             {
                 llaves[i, j] = MetodosAuxiliares.ajustaCadena(llaves[i, j], longitud);
             }
         }
     }
 }