Beispiel #1
0
        //Untested
        public void InsertNonFull(RTreeNode x, Rectangle k)
        {
            if (x.IsLeaf)
            {
                x.AddKey(k);
            }
            else
            {
                int i = comparer(x.GetSubRectangles(), k);

                if (x.GetPointer(i).NumberOfKeys == 2 * this.MinimumDegree - 1)
                {
                    SplitTheNode(x, i);
                }

                InsertNonFull(x.GetPointer(i), k);

                x.FixBoundary();
            }
        }
Beispiel #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);
        }