Example #1
0
 public void Put(Rectangle r, IPersistent obj)
 {
     if (!obj.IsPersistent())
     {
         ((StorageImpl)Storage).storeObject(obj);
     }
     if (root == null)
     {
         root   = new RtreePage(obj, r);
         height = 1;
     }
     else
     {
         RtreePage p = root.insert(r, obj, height);
         if (p != null)
         {
             root    = new RtreePage(root, p);
             height += 1;
         }
     }
     n += 1;
     Modify();
 }
Example #2
0
 internal RtreePage insert(Rectangle r, IPersistent obj, int level)
 {
     Load();
     Modify();
     if (--level != 0)
     {
         // not leaf page
         int  i, mini = 0;
         long minIncr = Int64.MaxValue;
         long minArea = Int64.MaxValue;
         for (i = 0; i < n; i++)
         {
             long area = b[i].r.Area();
             long incr = Rectangle.JoinArea(b[i].r, r) - area;
             if (incr < minIncr)
             {
                 minIncr = incr;
                 minArea = area;
                 mini    = i;
             }
             else if (incr == minIncr && area < minArea)
             {
                 minArea = area;
                 mini    = i;
             }
         }
         RtreePage p = (RtreePage)b[mini].p;
         RtreePage q = p.insert(r, obj, level);
         if (q == null)
         {
             // child was not split
             b[mini].r.Join(r);
             return(null);
         }
         else
         {
             // child was split
             b[mini] = new Branch(p.cover(), p);
             return(addBranch(new Branch(q.cover(), q)));
         }
     }
     else
     {
         return(addBranch(new Branch(r, obj)));
     }
 }
 internal RtreePage insert(Storage storage, Rectangle r, object obj, int level)
 {
     Modify();
     if (--level != 0)
     {
         // not leaf page
         int  i, mini = 0;
         long minIncr = long.MaxValue;
         long minArea = long.MaxValue;
         for (i = 0; i < n; i++)
         {
             long area = b[i].Area();
             long incr = Rectangle.JoinArea(b[i], r) - area;
             if (incr < minIncr)
             {
                 minIncr = incr;
                 minArea = area;
                 mini    = i;
             }
             else if (incr == minIncr && area < minArea)
             {
                 minArea = area;
                 mini    = i;
             }
         }
         RtreePage p = (RtreePage)branch[mini];
         RtreePage 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 Rectangle(r), obj));
     }
 }