Exemple #1
0
 internal RtreeRnPage(Storage storage, RtreeRnPage root, RtreeRnPage p)
 {
     branch        = storage.CreateLink(card);
     branch.Length = card;
     b             = new RectangleRn[card];
     n             = 2;
     setBranch(0, root.cover(), root);
     setBranch(1, p.cover(), p);
 }
 internal RtreeRnPage(Storage storage, RtreeRnPage root, RtreeRnPage p)
 {
     branch = storage.CreateLink(card);
     branch.Length = card;
     b = new RectangleRn[card];
     n = 2;
     setBranch(0, root.cover(), root);
     setBranch(1, p.cover(), p);
 }
Exemple #3
0
 internal RtreeRnPage insert(Storage storage, RectangleRn r, object obj, int level)
 {
     Modify();
     if (--level != 0)
     {
         // not leaf page
         int    i, mini = 0;
         double minIncr = Double.MaxValue;
         double minArea = Double.MaxValue;
         for (i = 0; i < n; i++)
         {
             double area = b[i].Area();
             double incr = RectangleRn.JoinArea(b[i], r) - area;
             if (incr < minIncr)
             {
                 minIncr = incr;
                 minArea = area;
                 mini    = i;
             }
             else if (incr == minIncr && area < minArea)
             {
                 minArea = area;
                 mini    = i;
             }
         }
         RtreeRnPage p = (RtreeRnPage)branch[mini];
         RtreeRnPage q = p.insert(storage, r, obj, level);
         if (q == null)
         {
             // child was not split
             b[mini].Join(r);
             return(null);
         }
         else
         {
             // child was split
             setBranch(mini, p.cover(), p);
             return(addBranch(storage, q.cover(), q));
         }
     }
     else
     {
         return(addBranch(storage, new RectangleRn(r), obj));
     }
 }
Exemple #4
0
 internal int remove(RectangleRn r, object obj, int level, ArrayList reinsertList)
 {
     if (--level != 0)
     {
         for (int i = 0; i < n; i++)
         {
             if (r.Intersects(b[i]))
             {
                 RtreeRnPage pg            = (RtreeRnPage)branch[i];
                 int         reinsertLevel = pg.remove(r, obj, level, reinsertList);
                 if (reinsertLevel >= 0)
                 {
                     if (pg.n >= card / 2)
                     {
                         setBranch(i, pg.cover(), pg);
                         Modify();
                     }
                     else
                     {
                         // not enough entries in child
                         reinsertList.Add(pg);
                         reinsertLevel = level - 1;
                         removeBranch(i);
                     }
                     return(reinsertLevel);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < n; i++)
         {
             if (branch.ContainsElement(i, obj))
             {
                 removeBranch(i);
                 return(0);
             }
         }
     }
     return(-1);
 }