Exemplo n.º 1
0
        //Metodo que se encarga de leer el archivo para actualizar de manera logica la lista de nodos
        public void actualizaListaNodo()
        {
            BinaryReader br = new BinaryReader(archArb);
            long         dicNod;

            char[] Tipo;
            long   dirPun;
            int    clv;
            bool   bandFinClv = true;

            r = 0;
            int  posAct   = 0;
            int  posIni   = 0;
            bool masNodos = true;

            while (true)
            {
                archArb.Seek((int)posIni, SeekOrigin.Begin);
                posIni = posAct;
                r      = 0;
                Nodo no = new Nodo();
                dicNod     = br.ReadInt64();
                Tipo       = br.ReadChars(1);
                no.dirNodo = dicNod;
                no.tipo    = Tipo.ElementAt(0);
                posAct    += 9;
                r          = 0;
                while (br.ReadInt64() != -1 && no.K.Count < n - 1)
                {
                    archArb.Seek(posAct, SeekOrigin.Begin);
                    dirPun = br.ReadInt64();
                    r      = 0;
                    if (no.tipo == 'H' || no.dirNodo == 0)
                    {
                        clv = br.ReadInt32();
                        no.K.Add(clv);
                        no.P.Add(dirPun);
                        posAct += 12;
                        r       = 0;
                    }
                    else
                    {
                        r   = 0;
                        clv = br.ReadInt32();
                        r   = 0;
                        if (clv != -1)
                        {
                            no.K.Add(clv);
                        }
                        no.P.Add(dirPun);
                        posAct += 12;
                        r       = 0;
                    }
                    r = 0;
                    if (br.ReadInt64() == -1)//No hay mas claves
                    {
                        bandFinClv = false;
                        r          = 0;
                    }
                    r = 0;
                    archArb.Seek(posAct, SeekOrigin.Begin);
                }
                r = 0;
                if (no.P.Count == n - 1 && no.tipo == 'R' && no.dirNodo == 0)
                {
                    r = 0;
                    archArb.Seek(posIni + 57, SeekOrigin.Begin);
                    long val = br.ReadInt64();
                    r = 0;
                    no.P.Add(val);
                }

                if (no.P.Count == n - 1 && no.tipo == 'H')
                {
                    r = 0;
                    archArb.Seek(posIni + 57, SeekOrigin.Begin);
                    no.P.Add(br.ReadInt64());
                    r = 0;
                }

                if (no.P.Count == n - 1 && no.tipo != 'H')
                {
                    r = 0;
                    archArb.Seek(posIni + 57, SeekOrigin.Begin);
                    long val = br.ReadInt64();
                    if (val != -1)
                    {
                        no.P.Add(val);
                    }
                    r = 0;
                }


                if (posIni + 65 == archArb.Length)
                {
                    masNodos = false;

                    r = 0;
                }

                r = 0;

                if (!masNodos)//llego al final y ya no tiene mas campos que agregar
                {
                    lisNodo.Add(no);
                    masNodos = true;
                    break;
                }
                else
                {
                    lisNodo.Add(no);
                    posIni += 65;
                }
                posAct = posIni;
            }
            r = 0;
        }