////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21DEC2008  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        internal override AbstractNode ReadNode(int page)
        {
            if (page < 0)
            {
                throw new ArgumentException("Page number cannot be negative.");
            }

            try
            {
                DataReader.Seek(_reader, _offset + HEADER_SIZE + page * PageSize);

                byte[] b = new byte[PageSize];
                int l = _reader.Read(b, 0, b.Length);
                if (-1 == l)
                {
                    throw new PageFaultException("EOF found while trying to read page "
                            + page + ".");
                }

                BinaryReader ds = new BinaryReader(new MemoryStream(b));

                int parent = DataReader.ReadInt(ds);
                if (parent == EMPTY_PAGE)
                {
                    throw new PageFaultException("Page " + page + " is empty.");
                }

                int level = DataReader.ReadInt(ds);
                int usedSpace = DataReader.ReadInt(ds);

                AbstractNode n;
                if (level != 0)
                {
                    n = new Index(Tree, parent, page, level);
                }
                else
                {
                    n = new Leaf(Tree, parent, page);
                }

                n.Parent = parent;
                n.Level = level;
                n.UsedSpace = usedSpace;

                double[] p1 = new double[Dimension];
                double[] p2 = new double[Dimension];

                for (int i = 0; i < usedSpace; i++)
                {
                    for (int j = 0; j < Dimension; j++)
                    {
                        p1[j] = DataReader.ReadDouble(ds);
                        p2[j] = DataReader.ReadDouble(ds);
                    }

                    n.Data[i] = new HyperCube(new Point(p1), new Point(p2));
                    n.Branches[i] = DataReader.ReadInt(ds);
                }

                return n;
            }
            catch (IOException)
            {

                return null;
            }
        }
Exemple #2
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21DEC2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        internal override AbstractNode ReadNode(int page)
        {
            if (page < 0)
            {
                throw new ArgumentException("Page number cannot be negative.");
            }

            try
            {
                DataReader.Seek(_reader, _offset + HEADER_SIZE + page * PageSize);

                byte[] b = new byte[PageSize];
                int    l = _reader.Read(b, 0, b.Length);
                if (-1 == l)
                {
                    throw new PageFaultException("EOF found while trying to read page "
                                                 + page + ".");
                }

                BinaryReader ds = new BinaryReader(new MemoryStream(b));

                int parent = DataReader.ReadInt(ds);
                if (parent == EMPTY_PAGE)
                {
                    throw new PageFaultException("Page " + page + " is empty.");
                }

                int level     = DataReader.ReadInt(ds);
                int usedSpace = DataReader.ReadInt(ds);

                AbstractNode n;
                if (level != 0)
                {
                    n = new Index(Tree, parent, page, level);
                }
                else
                {
                    n = new Leaf(Tree, parent, page);
                }

                n.Parent    = parent;
                n.Level     = level;
                n.UsedSpace = usedSpace;

                double[] p1 = new double[Dimension];
                double[] p2 = new double[Dimension];

                for (int i = 0; i < usedSpace; i++)
                {
                    for (int j = 0; j < Dimension; j++)
                    {
                        p1[j] = DataReader.ReadDouble(ds);
                        p2[j] = DataReader.ReadDouble(ds);
                    }

                    n.Data[i]     = new HyperCube(new Point(p1), new Point(p2));
                    n.Branches[i] = DataReader.ReadInt(ds);
                }

                return(n);
            }
            catch (IOException)
            {
                return(null);
            }
        }