void freeNode(NODE *node) { // release Name-Values (attribs) nameValue *nextNV = NULL; while (node->nV) { nextNV = node->nV->next; if (node->nV->bFreeValuePtr) { free(node->nV->value.s); } free(node->nV); node->nV = nextNV; } // release child if (node->child) { freeNode(node->child); } // release brother if (node->next) { freeNode(node->next); } free(node); }
void deleteLast(ListRef L) { NodeRef n; if (L == NULL) { printf( "Error: Called deleteLast() on NULL ListRef\n"); //exit(EXIT_FAILURE); } else if (isEmpty(L)) { printf( "Error: Called deleteLast() on empty ListRef\n"); //exit(EXIT_FAILURE); } if ( L->first == L->current ) { L->current = NULL; } if (L->length == 1) { freeNode(&(L->last)); L->last = NULL; L->first = NULL; } else { n = L->last; L->last = n->prev; n->prev->next = NULL; n->prev = NULL; freeNode(&n); n = NULL; } L->length--; }
void deleteNodeAt(int i) { if (i == 0) { // Removing head Node *tmp = head; head = head->next; tmp->next = NULL; freeNode(tmp); } else { int j = 0; Node *node = head; Node *prev = NULL; while (j < i) { prev = node; node = node->next; j++; } prev->next = node->next; node->next = NULL; freeNode(node); } size--; }
/** * This method is the deconstructor for the List class */ void freeList(ListPtr list) { if (list == NULL ) { return; } if (list->size == 0) { free(list); return; } if (list->size == 1 && list->head != NULL ) { freeNode(list->head, list->freeObject); free(list); return; } if (list->size < 0 || (list->head != NULL && list->head->data == NULL) || (list->tail!= NULL && list->tail->data == NULL)) return; NodePtr temp = list->head; while (temp->next != NULL ) { NodePtr tempPrev = temp; temp = temp->next; freeNode(tempPrev, list->freeObject); } freeNode(temp, list->freeObject); free(list); return; }
bTreeNode bTree::findBro(bTreeNode& node){ bTreeNode par = assignNode(node.parentPtr); if(findPath.back() > 0 && findPath.back() < par.valNum) { bTreeNode l = assignNode(par.ptrList[findPath.back()-1]); bTreeNode r = assignNode(par.ptrList[findPath.back()+1]); freeNode(par); if(l.valNum<r.valNum) { freeNode(r); return l; } else { freeNode(l); return r; } } freeNode(par); if(findPath.back() > 0) return assignNode(par.ptrList[findPath.back()-1]); if(findPath.back() < par.valNum) return assignNode(par.ptrList[findPath.back()+1]); return bTreeNode(); }
void taskwdAnyRemove(void *key) { struct mNode *pm; struct aNode *pa; taskwdInit(); epicsMutexMustLock(mLock); pm = (struct mNode *)ellFirst(&mList); while (pm) { if (pm->funcs == &anyFuncs) { pa = (struct aNode *)pm->usr; if (pa->key == key) { ellDelete(&mList, (void *)pm); freeNode((union twdNode *)pa); freeNode((union twdNode *)pm); epicsMutexUnlock(mLock); return; } } pm = (struct mNode *)ellNext(&pm->node); } epicsMutexUnlock(mLock); errlogPrintf("taskwdAnyRemove: Unregistered key %p\n", key); }
Node convertAttributesToText (Node node) { char* str; int len, at, i; Node ret = 0, examine = node->firstChild, prevExamine; AttributeData ad; if (node->type != AttributeGroup) return 0; /* We've stored the first child in examine, so we can already free the parent */ freeNode (node); while (examine) /* should be an Attribute node */ { ad = examine->data.attrdata; /* first turn attribute name, equals sign (if any) and * opening apostrophe or quotes (if any) into one string */ len = strlen (ad->name); at = len; len += ad->spacesAfterName; if (ad->type > 0) { len++; /* '=' */ len += ad->spacesAfterEquals; if (ad->type > 1) len++; /* ' or " */ } len++; /* trailing '\0' */ str = (char*) malloc (len * sizeof (char)); memcpy (str, ad->name, at * sizeof (char)); while (ad->spacesAfterName--) str[at++] = ' '; if (ad->type > 0) { str[at++] = '='; while (ad->spacesAfterEquals--) str[at++] = ' '; if (ad->type == 2) str[at++] = '\''; else if (ad->type == 3) str[at++] = '"'; } str[at] = '\0'; ret = makeTextBlock2 (ret, newNodeS (TextToken, str), examine->firstChild); if (ad->type > 1 || (ad->type == 1 && ad->spacesAfterValue > 0)) { at = ad->type > 1 ? 1 : 0; len = at + ad->spacesAfterValue; str = (char*) malloc (len * sizeof (char)); if (ad->type == 2) str[0] = '\''; else if (ad->type == 3) str[0] = '"'; while (ad->spacesAfterValue--) str[at++] = ' '; str[at] = '\0'; ret = makeTextBlock (ret, newNodeS (TextToken, str)); } prevExamine = examine; examine = examine->nextSibling; freeNode (prevExamine); } return ret; }
int recDelete(rect *r, node *n, int pos){ int i,j; node *n1, *n2; if(n->leaf){ for(i = 0; i < n->size; ++i) if(n->values[i]->child == pos){ deleteValue(n, i); writeNode(n); return TRUE; } return FALSE; } for(i = 0; i < n->size; ++i) if(intersect(r, n->values[i]->r)){ n1 = readNode(n->values[i]->child); if(recDelete(r, n1, pos)){ n->values[i]->r = dupRect(n1->MBR); if(n1->size < b ) underflow(n, n1, i); else{ refreshMBR(n); writeNode(n); freeNode(n1); } return TRUE; } else freeNode(n1); } return FALSE; }
void removeFromList(Node** head, int offset) { //int location = findOffset(head, offset); printf("\n removing from list "); Node* p = *head; int i =0; if((*head)->data->offset == offset) { *head = (*head)->next; freeNode(p); return; } while(p->next!=NULL) { if(p->next->data->offset == offset) break; p = p->next; } printf("\n printing value of prev node%d", p->data->offset); Node* q = p->next; if(p->next!=NULL) p->next = p->next->next; freeNode(q); printf("\n removed node"); }
std::vector<unsigned int> bTree::findGreater(Index ind, bool equal){ unsigned int i; std::vector<unsigned int> res; bTreeNode cur = findFirstNode(ind); for (i = 0; i < cur.valNum; ++i) { if(cur.indexList[i]>=ind) break; } if(i>=cur.valNum) { freeNode(cur); if(cur.ptrList.back()==0) return res; cur = assignNode(cur.ptrList.back()); i = 0; } while(true) { if(equal || cur.indexList[i]!=ind) res.push_back(cur.ptrList[i]); i++; if(i>=cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } freeNode(cur); return res; }
std::vector<unsigned int> bTree::findAll(Index ind){ unsigned int i; std::vector<unsigned int> res; bTreeNode cur = findFirstNode(ind); for (i = 0; i < cur.valNum; ++i) { if(cur.indexList[i]==ind) break; } if(i>=cur.valNum) { freeNode(cur); if(cur.ptrList.back()==0) return res; cur = assignNode(cur.ptrList.back()); if(cur.indexList.front()!=ind) return res; i = 0; } while(cur.indexList[i]==ind) { res.push_back(cur.ptrList[i++]); if(i==cur.valNum) { if(cur.ptrList[i]==0) break; freeNode(cur); cur = assignNode(cur.ptrList[i]); i = 0; } } freeNode(cur); return res; }
bTreeNode bTree::findFirstNode(Index ind){ bTreeNode cur = assignNode(root); bTreeNode par = cur; findPath.clear(); int ser; while(cur.type!=LEAF) { for (ser = 0; ser < cur.valNum; ++ser) { if(ind<cur.indexList[ser]) break; } findPath.push_back(ser); if(cur.type!=ROOT) { freeNode(par); par = cur; } cur = assignNode(cur.ptrList[ser]); } freeNode(par); return cur; }
void freeList(ListPtr L) { NodePtr tempNode, currentNode; if (L==NULL){ return; } if (L->head == NULL ) { free(L); return; } if (L->head == L->tail) { freeNode(L->head, (void *) L->freeObject); free(L); return; } currentNode = L->head; while (currentNode != NULL ) { tempNode = currentNode; currentNode = currentNode->next; freeNode(tempNode, (void *) L->freeObject); } free(L); }
/* Recursively deallocate the memory assigned to this node's subtree */ void freeNode(priorityQueueEntry* node) { if(node->childl) freeNode(node->childl); if(node->childr) freeNode(node->childr); free(node); }
void freeNode( Node *node ) { if (node != NULL) { freeNode( node->left ); freeNode( node->right ); } free( node ); }
/* freeNode: free node created with node() */ void freeNode(struct node *node) { if (node == NULL) return; freeNode(node->child); freeNode(node->next); }
/*! \internal */ void QGeneralAreaAllocator::freeNode(Node *node) { if (node) { freeNode(node->left); freeNode(node->right); } delete node; }
void freeNode(Node *node) { if (node == NULL) return; freeNode(node->left); freeNode(node->right); free(node); }
// Free the node void Tree::freeNode(Node* leaf) { if ( leaf != NULL ) { freeNode(leaf->Left()); freeNode(leaf->Right()); delete leaf; } }
/* ============================================================================= * freeNode * ============================================================================= */ static void freeNode (node_t* n) { if (n) { freeNode(n->l); freeNode(n->r); releaseNode(n); } }
void freeNode(struct TreeNode *ptr) { if(ptr -> left) { freeNode(ptr -> left); } if(ptr -> right) { freeNode(ptr -> right); } free(ptr); }
static void freeNode(AVLNode *node){ if(node != nullptr){ // nothing to do if tree empty freeNode(node->left()); // free nodes of left child freeNode(node->right());// free nodes of right child delete node; } }
/* removes the given node from the given list. the other node is the prev node returns the updated curr node*/ listNode* removeNode(linkedList* list , listNode* prev , listNode* curr){ if (prev==NULL) { list->first = curr->next; freeNode(curr); return list->first; } prev->next = curr->next; freeNode(curr); return prev->next; }
void bTree::insertIndex(Index ind){ unsigned int i; bTreeNode cur = findFirstNode(ind); for (i = 0; i < cur.valNum; ++i) { if (ind<cur.indexList[i]) break; } cur.dirty = true; //if(i==cur.valNum) //cur.indexList.push_back(ind); //else //cur.indexList.insert(cur.indexList.begin()+i,ind); //std::cout<<"num:"<<cur.valNum<<std::endl; if (cur.valNum>0) cur.indexList.insert(cur.indexList.begin()+i,ind); else cur.indexList.push_back(ind); cur.valNum++; cur.ptrList.insert(cur.ptrList.begin()+i,ind.getTuple()); //std::cout<<ind.getInt()<<std::endl; //cur.testOutput(); //std::cout<<std::endl; if (cur.isFull()) { bTreeNode newNode = createNode(LEAF); unsigned int half = cur.valNum/2; newNode.valNum = cur.valNum - half; for (i = 0; i < newNode.valNum; ++i) { newNode.indexList.push_back(cur.indexList[i+half]); newNode.ptrList.push_back(cur.ptrList[i+half]); } newNode.ptrList.push_back(cur.ptrList.back()); newNode.parentPtr = cur.parentPtr; cur.indexList.erase(cur.indexList.begin()+half,cur.indexList.end()); cur.ptrList.erase(cur.ptrList.begin()+half,cur.ptrList.end()); cur.ptrList.push_back(newNode.blockNo); cur.valNum = half; freeNode(newNode); freeNode(cur); insertNode(newNode.parentPtr,newNode.blockNo,findPath.back(),newNode.indexList.front()); } else freeNode(cur); return; }
bTree::bTree(string name, indexType t, int length, buffer* bfm){ bm = bfm; indexName = name; indtype = t; charLength = length; bm->createNewFile(indexName); bTreeNode r = createNode(ROOT); bTreeNode l = createNode(LEAF); r.ptrList.push_back(l.blockNo); l.ptrList.push_back(0); root = r.blockNo; l.parentPtr = root; freeNode(r); freeNode(l); }
/* This function removes the node in the list that matches the argument string str */ void removeStr(StrList** pbegin,StrList** pend,const char* str) { StrList* ptemp; /* temporary node pointer */ StrList* pprev; /* pointer to previous node in list */ StrList* pcurrent; /* pointer to current node in list */ /* delete first node if it has a corresponding strdata content to the input argument str */ if (*pbegin != NULL) { if ( !strcmp((*pbegin)->strdata,str) ){ /* Remove first node */ ptemp = *pbegin; /* hold onto node being removed */ *pbegin = (*pbegin)->pnext; /* de-thread the node */ if (*pbegin!=NULL) (*pbegin)->pprev = NULL; /* Change pointer back if not last in list */ /* free the memory of the node ... */ freeNode(&ptemp); printf("Node with %s has been removed.\n", str); } else { pprev = *pbegin; /* Iterator: Pointer to previous node */ pcurrent = (*pbegin)->pnext; /* Iterator: Pointer to current node */ /* loop to find the correct location in the list */ while ( pcurrent != NULL && strcmp(pcurrent->strdata,str) ) { pprev = pcurrent; /* walk to ... */ pcurrent = pcurrent->pnext; /* ... next node */ } /* delete node at pcurrent */ if ( pcurrent != NULL ) { ptemp = pcurrent; pprev->pnext = pcurrent->pnext; if (pcurrent->pnext == NULL) { /* This is the last element. Update the end pointer */ pend = NULL; } else { pcurrent->pnext->pprev = pprev; } freeNode(&ptemp); printf("Node with %s has been removed.\n", str); } else { printf("Node with %s has not been found.\n", str); } } } else { printf("List empty, nothing to remove.\n"); } }
/* * deleteCurrent() * Deletes element at curr in L * Pre: !isEmpty(L); !offEnd(L) */ void deleteCurrent(ListRef L) { if ( L == NULL ) { printf("List Error: calling deleteCurrent() on NULL ListRef\n"); exit(1); } if ( isEmpty(L) ) { printf("List Error: calling deleteCurrent() on an empty List\n"); exit(1); } if ( offEnd(L) ) { printf("List Error: calling deleteCurrent() on a NULL pointer\n"); exit(1); } NodeRef N = NULL; N = L->curr; if ( getLength(L) > 1 ) { if ( L->curr->prev == NULL ) { L->front = L->curr->next; L->curr->next = NULL; }else if ( L->curr->next == NULL ) { L->back = L->curr->prev; L->curr->prev = NULL; }else { L->curr->prev->next = L->curr->next; L->curr->next->prev = L->curr->prev; L->curr->prev = L->curr->next = NULL; } L->curr = NULL; }else { L->front = L->back = L->curr = NULL; } --L->length; freeNode(&N); }
void JunctionPoints::refresh(void) { JunctionSelection* selection = static_cast<JunctionSelection*>( getSceneManipulator()->_getSelection("JunctionSelection")); const JunctionSelection::JunctionMap& junctions = selection->getJunctions(); DisplayNodes newDisplayNodes; // Use existing point if possible for (JunctionSelection::JunctionMap::const_iterator it = junctions.begin(); it != junctions.end(); ++it) { const JunctionSelection::Junction& junction = it->second; Ogre::Vector3 pos = getTerrainData()->_getPosition(junction.x, junction.z); DisplayNodes::iterator found = mDisplayNodes.find(Ogre::Vector4(pos.x, pos.y, pos.z, junction.weight)); Ogre::SceneNode* node = NULL; if (found != mDisplayNodes.end()) { node = found->second; mDisplayNodes.erase(found); } newDisplayNodes.insert(DisplayNodes::value_type(Ogre::Vector4(pos.x, pos.y, pos.z, junction.weight), node)); } // Build new point and adjust position for (DisplayNodes::iterator it = newDisplayNodes.begin(); it != newDisplayNodes.end(); ++it) { if (!it->second) { if (!mDisplayNodes.empty()) { DisplayNodes::iterator found = mDisplayNodes.begin(); it->second = found->second; mDisplayNodes.erase(found); } else { it->second = allocNode(); } it->second->setPosition(it->first.x,it->first.y,it->first.z); // 根据节点的权重来设置节点所挂物体的材质颜色 Ogre::MaterialPtr material = createPureColourMaterial(Ogre::ColourValue(it->first.w,(1.0f-it->first.w),0.0f)); // 设置节点的材质 static_cast<Ogre::Entity *>(it->second->getAttachedObject(0))->setMaterialName(material->getName()); } } // Hide extra points for (DisplayNodes::const_iterator it = mDisplayNodes.begin(); it != mDisplayNodes.end(); ++it) { freeNode(it->second); } std::swap(newDisplayNodes, mDisplayNodes); }
void LSQ_DestroySequence(LSQ_HandleT handle){ if(NULL == handle) return; TreePtr tree = handle; destroySubTree(tree->root); freeNode(tree->root); free(tree); }
/* ============================================================================= * net_alloc * ============================================================================= */ net_t* net_alloc (long numNode) { net_t* netPtr; netPtr = (net_t*)SEQ_MALLOC(sizeof(net_t)); if (netPtr) { vector_t* nodeVectorPtr = vector_alloc(numNode); if (nodeVectorPtr == NULL) { SEQ_FREE(netPtr); return NULL; } long i; for (i = 0; i < numNode; i++) { net_node_t* nodePtr = allocNode(i); if (nodePtr == NULL) { long j; for (j = 0; j < i; j++) { nodePtr = (net_node_t*)vector_at(nodeVectorPtr, j); freeNode(nodePtr); } vector_free(nodeVectorPtr); SEQ_FREE(netPtr); return NULL; } bool_t status = vector_pushBack(nodeVectorPtr, (void*)nodePtr); assert(status); } netPtr->nodeVectorPtr = nodeVectorPtr; } return netPtr; }