void FreeList(PT_LIST_LINKNODE ptListHead) { PT_NODE ptCurNode = NULL; PT_LIST_LINKNODE ptNextNode = NULL; PT_LIST_LINKNODE ptLinkNode = NULL; // exception handle, list is empty or error if ( !ptListHead->next || !ptListHead->prev ) { return; } list_for_each_safe(ptListHead, ptLinkNode, ptNextNode){ ptCurNode = list_entry(ptLinkNode, T_NODE, tLinkNode); list_del(&(ptCurNode->tLinkNode)); FreeListNode(ptCurNode); ptCurNode = NULL; }
RTREE_TEMPLATE bool RTREE_QUAL::RemoveRect(Rect* a_rect, const DATATYPE& a_id, Node** a_root) { ASSERT(a_rect && a_root); ASSERT(*a_root); ListNode* reInsertList = NULL; if (!RemoveRectRec(a_rect, a_id, *a_root, &reInsertList)) { // Found and deleted a data item // Reinsert any branches from eliminated nodes while (reInsertList) { Node* tempNode = reInsertList->m_node; for (int index = 0; index < tempNode->m_count; ++index) { // TODO go over this code. should I use (tempNode->m_level - 1)? InsertRect(tempNode->m_branch[index], a_root, tempNode->m_level); } ListNode* remLNode = reInsertList; reInsertList = reInsertList->m_next; FreeNode(remLNode->m_node); FreeListNode(remLNode); } // Check for redundant root (not leaf, 1 child) and eliminate TODO replace // if with while? In case there is a whole branch of redundant roots... if ((*a_root)->m_count == 1 && (*a_root)->IsInternalNode()) { Node* tempNode = (*a_root)->m_branch[0].m_child; ASSERT(tempNode); FreeNode(*a_root); *a_root = tempNode; } return false; } else { return true; } }