Beispiel #1
0
 /// <summary>
 /// RTree constructor. Initializes the root.
 /// </summary>
 public RTree()
 {
     root = new NodeRecord <T> {
         Node = new RTreeNode <T>(Leaf: true)
     };
 }
Beispiel #2
0
        /// <summary>
        /// Utilizes the Quadradic split algorithm to determine where each
        /// of the records go - either to group one or group two.
        /// </summary>
        /// <param name="newItem"></param>
        /// <returns></returns>
        public NodeRecord <T> SplitQuadradic(IndexRecord <T> newItem)
        {
            List <IndexRecord <T> > itemsToBeAssigned = records;

            itemsToBeAssigned.Add(newItem);

            IndexRecord <T> A, B;

            // QS1.
            pickSeeds(itemsToBeAssigned, out A, out B);
            itemsToBeAssigned.Remove(A);
            itemsToBeAssigned.Remove(B);

            NodeRecord <T> groupOne = new NodeRecord <T>()
            {
                BBox = A.BBox, Node = new RTreeNode <T>(isLeaf)
            };
            NodeRecord <T> groupTwo = new NodeRecord <T>()
            {
                BBox = B.BBox, Node = new RTreeNode <T>(isLeaf)
            };

            groupOne.Node.TryInsert(A);
            groupTwo.Node.TryInsert(B);

            // QS2.
            while (itemsToBeAssigned.Count > 0)
            {
                // QS3.
                int d1, d2;
                var next = pickNext(itemsToBeAssigned, groupOne, groupTwo, out d1, out d2);
                if (d1 < d2)
                {
                    groupOne.TryInsert(next);
                }
                else if (d2 < d1)
                {
                    groupTwo.TryInsert(next);
                }
                else
                {
                    // Insert to whichever is smaller.
                    if (groupOne.Node.GetRecordCount() < groupTwo.Node.GetRecordCount())
                    {
                        groupOne.TryInsert(next);
                    }
                    else
                    {
                        groupTwo.TryInsert(next);
                    }
                }

                itemsToBeAssigned.Remove(next);

                // QS2.
                if (groupOne.Node.GetRecordCount() + itemsToBeAssigned.Count <= m)
                {
                    while (itemsToBeAssigned.Count > 0)
                    {
                        groupOne.TryInsert(itemsToBeAssigned.First());
                        itemsToBeAssigned.Remove(itemsToBeAssigned.First());
                    }
                }

                // QS2.
                if (groupTwo.Node.GetRecordCount() + itemsToBeAssigned.Count <= m)
                {
                    while (itemsToBeAssigned.Count > 0)
                    {
                        groupTwo.TryInsert(itemsToBeAssigned.First());
                        itemsToBeAssigned.Remove(itemsToBeAssigned.First());
                    }
                }
            }

            // Set this equal to group two.
            records = groupTwo.Node.records;
            return(groupOne);
        }