Exemple #1
0
        public Tree(int Order, string Path, ICreateFixedSizeText <T> createFixedSizeText, int c)
        {
            this.Order = Order;
            this.Path  = Path;
            this.createFixedSizeText = createFixedSizeText;

            var buffer = new byte[Header.FixedSize];

            using (var fs = new FileStream(Path, FileMode.OpenOrCreate))
            {
                fs.Read(buffer, 0, Header.FixedSize);
            }

            var HeaderString = ByteGenerator.ConvertToString(buffer);
            var values       = HeaderString.Split(Util.Separator);

            this.Root         = Convert.ToInt16(values[0]);
            this.Order        = Convert.ToInt16(values[1]);
            this.LastPosition = Convert.ToInt16(values[2]);
        }
Exemple #2
0
        internal Node <T> ReadNode(string Path, int Order, int Root, int ID, ICreateFixedSizeText <T> createFixedSizeText)
        {
            int Father = 0;

            if (ID == Root)
            {
                Father = Util.NullPointer;
            }

            Node <T> node = new Node <T>(Order, ID, Father, createFixedSizeText);

            int HeaderSize = Header.FixedSize;

            byte[] buffer;

            if (ID <= Root)
            {
                buffer = new byte[node.FixedSize(node.Father)];
                using (var fs = new FileStream(Path, FileMode.OpenOrCreate))
                {
                    fs.Seek((HeaderSize + ((ID - 1) * node.FixedSize(1))), SeekOrigin.Begin);
                    fs.Read(buffer, 0, node.FixedSize(node.Father));
                }
            }
            else
            {
                buffer = new byte[node.FixedSize(node.Father)];
                using (var fs = new FileStream(Path, FileMode.OpenOrCreate))
                {
                    fs.Seek((HeaderSize + ((ID - 1) * node.FixedSize(1)) + node.FixedSize(Util.NullPointer)), SeekOrigin.Begin);
                    fs.Read(buffer, 0, node.FixedSize(node.Father));
                }
            }



            var NodeString = ByteGenerator.ConvertToString(buffer);
            var Values     = NodeString.Split(Util.Separator);

            node.Father = Convert.ToInt32(Values[1]);

            //Hijos

            int DataLimit = Order;

            if (node.Father.Equals(Util.NullPointer))
            {
                DataLimit = (4 * (Order - 1)) / 3;
                int j = 0;
                for (int i = 2; i < DataLimit + 2; i++)
                {
                    node.Data[j] = createFixedSizeText.Create(Values[i]);
                    j++;
                }
                j = 0;
                int StartLimit = node.Data.Count + 2;
                for (int i = StartLimit; i < Values.Length - 1; i++)
                {
                    node.Children[j] = Convert.ToInt32(Values[i]);
                    j++;
                }
            }
            else
            {
                int j = 0;
                for (int i = 2; i < DataLimit + 1; i++)
                {
                    node.Data[j] = createFixedSizeText.Create(Values[i]);
                    j++;
                }
                j = 0;
                int StartLimit = node.Data.Count + 2;
                //Valores
                for (int i = StartLimit; i < Values.Length - 1; i++)
                {
                    node.Children[j] = Convert.ToInt32(Values[i]);
                    j++;
                }
            }


            return(node);
        }