Exemplo n.º 1
0
        //Untested
        public void SplitTheNode(RTreeNode parent, int childIndex)
        {
            RTreeNode y = parent.GetPointer(childIndex);

            int t = this.MinimumDegree;

            RTreeNode z = new RTreeNode();

            z.IsLeaf = y.IsLeaf;

            //z.AddRangeKeys(y.SkipKeys(t));

            if (y.IsLeaf)
            {
                z.AddRangeKeys(y.SkipKeys(t));

                //z.AddRangePointers(y.SkipPointers(t));

                y.RemoveRangeKeys(t, t - 1);
            }
            else
            {
                z.AddRangePointers(y.SkipPointers(t));

                y.RemoveRangePointers(t, t - 1);
            }

            parent.InsertPointer(childIndex + 1, z);
        }
Exemplo n.º 2
0
        //Untested
        public void SplitTheNode(RTreeNode parent, int childIndex)
        {
            RTreeNode y = parent.GetPointer(childIndex);

            parent.RemovePointer(y);

            int t = this.MinimumDegree;

            int firstChild, secondChild;

            y.FindTheMostDistantRectangles(out firstChild, out secondChild);

            RTreeNode firstNode = new RTreeNode(); firstNode.IsLeaf = y.IsLeaf;

            RTreeNode secondNode = new RTreeNode(); secondNode.IsLeaf = y.IsLeaf;

            if (y.IsLeaf)
            {
                firstNode.AddKey(y.GetKey(firstChild)); secondNode.AddKey(y.GetKey(secondChild));

                for (int i = 0; i < y.NumberOfKeys; i++)
                {
                    if (i == firstChild || i == secondChild)
                    {
                        continue;
                    }

                    if (firstNode.NumberOfKeys == y.NumberOfKeys - t)
                    {
                        secondNode.AddKey(y.GetKey(i));
                    }
                    else if (secondNode.NumberOfKeys == y.NumberOfKeys - t)
                    {
                        firstNode.AddKey(y.GetKey(i));
                    }
                    else
                    {
                        double firstEnlargement = firstNode.Boundary.GetEnlargementArea(y.GetKey(i));

                        double secondEnlargement = secondNode.Boundary.GetEnlargementArea(y.GetKey(i));

                        if (firstEnlargement < secondEnlargement)
                        {
                            firstNode.AddKey(y.GetKey(i));
                        }
                        else if (firstEnlargement > secondEnlargement)
                        {
                            secondNode.AddKey(y.GetKey(i));
                        }
                        else
                        {
                            if (firstNode.Boundary.GetArea() > secondNode.Boundary.GetArea())
                            {
                                secondNode.AddKey(y.GetKey(i));
                            }
                            else
                            {
                                firstNode.AddKey(y.GetKey(i));
                            }
                        }
                    }
                }
            }
            else
            {
                firstNode.AddPointer(y.GetPointer(firstChild)); secondNode.AddPointer(y.GetPointer(secondChild));

                for (int i = 0; i < y.NumberOfKeys; i++)
                {
                    if (i == firstChild || i == secondChild)
                    {
                        continue;
                    }

                    if (firstNode.NumberOfKeys == y.NumberOfKeys - t)
                    {
                        secondNode.AddPointer(y.GetPointer(i));
                    }
                    else if (secondNode.NumberOfKeys == y.NumberOfKeys - t)
                    {
                        firstNode.AddPointer(y.GetPointer(i));
                    }
                    else
                    {
                        double firstEnlargement = firstNode.Boundary.GetEnlargementArea(y.GetPointer(i).Boundary);

                        double secondEnlaregement = secondNode.Boundary.GetEnlargementArea(y.GetPointer(i).Boundary);

                        if (firstEnlargement < secondEnlaregement)
                        {
                            firstNode.AddPointer(y.GetPointer(i));
                        }
                        else if (firstEnlargement > secondEnlaregement)
                        {
                            secondNode.AddPointer(y.GetPointer(i));
                        }
                        else
                        {
                            if (firstNode.Boundary.GetArea() > secondNode.Boundary.GetArea())
                            {
                                secondNode.AddPointer(y.GetPointer(i));
                            }
                            else
                            {
                                firstNode.AddPointer(y.GetPointer(i));
                            }
                        }
                    }
                }
            }

            parent.InsertPointer(childIndex, firstNode);

            parent.InsertPointer(childIndex + 1, secondNode);
        }