return;
}
-/* Allocate space for a node in the list used in DeletRect to
- * store Nodes that are too empty.
- */
-static struct ListNode *RTreeNewListNode(void)
-{
- return calloc(1, sizeof(struct ListNode));
-}
-
-/* Add a node to the reinsertion list. All its branches will later
- * be reinserted into the index structure.
- */
-static int RTreeReInsert(Node_t * n, struct ListNode **ee)
-{
- struct ListNode *l;
-
- if (!(l = RTreeNewListNode()))
- return -1;
- l->node = n;
- l->next = *ee;
- *ee = l;
- return 0;
-}
-
RTree_t *RTreeOpen()
{
RTree_t *rtp;
return 0;
}
}
-
-static void FreeListNode(struct ListNode *p)
-{
- free(p);
-}
-
-/* Delete a data rectangle from an index structure.
-** Pass in a pointer to a Rect, the data of the record, ptr to ptr to root node.
-** Returns 1 if record not found, 0 if success.
-** RTreeDelete provides for eliminating the root.
-*/
-static int RTreeDelete2(RTree_t *, Rect_t *, void *, Node_t *,
- ListNode_t **);
-
-int RTreeDelete(RTree_t * rtp, Rect_t * r, void *data, Node_t ** nn)
-{
- Node_t *t;
- struct ListNode *reInsertList = NULL;
-
- assert(r && nn);
- assert(*nn);
- assert(data);
-
- rtp->Deleting = TRUE;
-
-# ifdef RTDEBUG
- fprintf(stderr, "RTreeDelete\n");
-# endif
-
- if (!RTreeDelete2(rtp, r, data, *nn, &reInsertList)) {
- /* found and deleted a data item */
- if (rtp->StatFlag)
- rtp->DeleteCount++;
- rtp->RectCount--;
-
- /* reinsert any branches from eliminated nodes */
- while (reInsertList) {
- t = reInsertList->node;
- for (size_t i = 0; i < NODECARD; i++) {
- if (t->branch[i].child) {
- RTreeInsert(rtp, &(t->branch[i].rect),
- t->branch[i].child, nn, t->level);
- rtp->EntryCount--;
- }
- }
- struct ListNode *e = reInsertList;
- reInsertList = reInsertList->next;
- RTreeFreeNode(rtp, e->node);
- FreeListNode(e);
- }
-
- /* check for redundant root (not leaf, 1 child) and eliminate */
- if ((*nn)->count == 1 && (*nn)->level > 0) {
- if (rtp->StatFlag)
- rtp->ElimCount++;
- rtp->EntryCount--;
- for (size_t i = 0; i < NODECARD; i++) {
- if ((t = (*nn)->branch[i].child))
- break;
- }
- RTreeFreeNode(rtp, *nn);
- *nn = t;
- }
- rtp->Deleting = FALSE;
- return 0;
- } else {
- rtp->Deleting = FALSE;
- return 1;
- }
-}
-
-/* Delete a rectangle from non-root part of an index structure.
-** Called by RTreeDelete. Descends tree recursively,
-** merges branches on the way back up.
-*/
-static int
-RTreeDelete2(RTree_t * rtp, Rect_t * r, void *data, Node_t * n,
- ListNode_t ** ee)
-{
- assert(r && n && ee);
- assert(data);
- assert(n->level >= 0);
-
- if (rtp->StatFlag)
- rtp->DeTouchCount++;
-
- if (n->level > 0) { /* not a leaf node */
- for (int i = 0; i < NODECARD; i++) {
- if (n->branch[i].child && Overlap(r, &(n->branch[i].rect))) {
- if (!RTreeDelete2(rtp, r, data, n->branch[i].child, ee)) { /*recurse */
- if (n->branch[i].child->count >= rtp->MinFill)
- n->branch[i].rect = NodeCover(n->branch[i].child);
- else { /* not enough entries in child, eliminate child node */
- RTreeReInsert(n->branch[i].child, ee);
- DisconBranch(n, i);
- rtp->EntryCount--;
- if (rtp->StatFlag)
- rtp->ElimCount++;
- }
- return 0;
- }
- }
- }
- return 1;
- } else { /* a leaf node */
- for (int i = 0; i < NODECARD; i++) {
- if (n->branch[i].child
- && n->branch[i].child == (Node_t *) data) {
- DisconBranch(n, i);
- rtp->EntryCount--;
- return 0;
- }
- }
- return 1;
- }
-}