Example #1
0
 internal int remove(Rectangle r, IPersistent obj, int level, ArrayList reinsertList)
 {
     Load();
     if (--level != 0)
     {
         for (int i = 0; i < n; i++)
         {
             if (r.Intersects(b[i].r))
             {
                 RtreePage pg            = (RtreePage)b[i].p;
                 int       reinsertLevel = pg.remove(r, obj, level, reinsertList);
                 if (reinsertLevel >= 0)
                 {
                     if (pg.n >= minFill)
                     {
                         b[i] = new Branch(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 (b[i].p == obj)
             {
                 removeBranch(i);
                 return(0);
             }
         }
     }
     return(-1);
 }
 internal int remove(Rectangle r, object obj, int level, ArrayList reinsertList)
 {
     if (--level != 0)
     {
         for (int i = 0; i < n; i++)
         {
             if (r.Intersects(b[i]))
             {
                 RtreePage pg            = (RtreePage)branch[i];
                 int       reinsertLevel = pg.remove(r, obj, level, reinsertList);
                 if (reinsertLevel >= 0)
                 {
                     if (pg.n >= minFill)
                     {
                         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);
 }
Example #3
0
        public void Remove(Rectangle r, IPersistent obj)
        {
            if (root == null)
            {
                throw new StorageError(StorageError.ErrorCode.KEY_NOT_FOUND);
            }
            ArrayList reinsertList  = new ArrayList();
            int       reinsertLevel = root.remove(r, obj, height, reinsertList);

            if (reinsertLevel < 0)
            {
                throw new StorageError(StorageError.ErrorCode.KEY_NOT_FOUND);
            }
            for (int i = reinsertList.Count; --i >= 0;)
            {
                RtreePage p = (RtreePage)reinsertList[i];
                for (int j = 0, pn = p.n; j < pn; j++)
                {
                    RtreePage q = root.insert(p.b[j].r, p.b[j].p, height - reinsertLevel);
                    if (q != null)
                    {
                        // root splitted
                        root    = new RtreePage(root, q);
                        height += 1;
                    }
                }
                reinsertLevel -= 1;
                p.Deallocate();
            }
            if (root.n == 1 && height > 1)
            {
                RtreePage newRoot = (RtreePage)root.b[0].p;
                root.Deallocate();
                root    = newRoot;
                height -= 1;
            }
            n -= 1;
            Modify();
        }