Exemplo n.º 1
0
/**
* Runs tests on the removeNode function by removing all the nodes in the list
**/
void removeNodeAllTest(ListPtr list, int count)
{
	int i;
	int testSize = count;
	for(i = 0; i < count; i++)
	{
		testSize--;
		NodePtr node = removeNode(list, search(list, testSize));
		if(node == NULL) {printf("Node is NULL"); continue;}
		//printf("i: %d jobid: %d size: %d testSize: %d tail: %d", i, node->data->jobid, list->size, testSize, list->tail->data->jobid );
		//printf("1: %d 2: %d 3: %d 4: %d", node->data->jobid != testSize, list->size != testSize, (list->head != NULL && list->head->data->jobid != 0), (list->tail != NULL && list->tail->data->jobid != testSize - 1));
		if(node->data->jobid != testSize
			|| list->size != testSize
			|| (list->head != NULL && list->head->data->jobid != 0)
			|| (list->tail != NULL && list->tail->data->jobid != testSize - 1)
		)
		{
			printf("\n%s\n%s\n", sep, "Error: removeNodeAll invalid");
			break;
		}
		freeNode(node);
	}
	if(DEBUG > 0)
		verifyRearAll(list, count);
}
Exemplo n.º 2
0
void mergeNodes(pugi::xml_node toNode, pugi::xml_node& fromNode)
{
  // Base case = both nodes are text nodes
  pugi::xml_text fromNodeText = fromNode.text();
  pugi::xml_text toNodeText = toNode.text();
  if (fromNodeText && toNodeText) {
    SBLog::info() << "Overwriting template value of \"" << toNode.name() << "\" from \"" << toNodeText.get() << "\" to \"" << fromNodeText.get() << "\"." << std::endl;
    toNodeText.set(fromNodeText.get());
    return;
  }

  // Calculate number of children in toNode
  unsigned maxDistance = std::distance(toNode.begin(), toNode.end());

  // Merge children
  for (pugi::xml_node fromNodeChild = fromNode.first_child(); fromNodeChild; fromNodeChild = fromNodeChild.next_sibling()) {
    // Find appropriate merge point
    pugi::xml_node toNodeChild = findSimilarNode(fromNodeChild, toNode, maxDistance);
    if (toNodeChild) {
      mergeNodes(toNodeChild, fromNodeChild);
    } else {
      toNode.append_copy(fromNodeChild);
    }
  }

  // Erase fromNode
  removeNode(fromNode);
}
Exemplo n.º 3
0
void DecreaseSelectionListLevelCommand::doApply()
{
    Node* startListChild;
    Node* endListChild;
    if (!canDecreaseListLevel(endingSelection(), startListChild, endListChild))
        return;

    Node* previousItem = startListChild->renderer()->previousSibling() ? startListChild->renderer()->previousSibling()->element() : 0;
    Node* nextItem = endListChild->renderer()->nextSibling() ? endListChild->renderer()->nextSibling()->element() : 0;
    Element* listNode = startListChild->parentElement();

    if (!previousItem) {
        // at start of sublist, move the child(ren) to before the sublist
        insertSiblingNodeRangeBefore(startListChild, endListChild, listNode);
        // if that was the whole sublist we moved, remove the sublist node
        if (!nextItem)
            removeNode(listNode);
    } else if (!nextItem) {
        // at end of list, move the child(ren) to after the sublist
        insertSiblingNodeRangeAfter(startListChild, endListChild, listNode);    
    } else if (listNode) {
        // in the middle of list, split the list and move the children to the divide
        splitElement(listNode, startListChild);
        insertSiblingNodeRangeBefore(startListChild, endListChild, listNode);
    }
}
Exemplo n.º 4
0
bst deleteNode( bst b, int x,int y , bst father ) {
  if ( b == NULL ) return b;
  if ( is_lower_than(x,y,b->x,b->y ) < 0 ) b->sx = deleteNode( b->sx, x,y, b );
  if ( is_lower_than(x,y,b->x,b->y ) > 0) b->dx = deleteNode( b->dx, x,y, b );
  if ( is_lower_than(x,y,b->x,b->y ) == 0) {
    if ( ( b->sx == NULL ) || ( b->dx == NULL ) ) b = removeNode( b, father );
    else {
      bst m = b->sx, f = b;
      while ( m->dx ) { f = m; m = m->dx; }
      b->x = m->x;
	  b->y = m->y;
      m = removeNode( m, f );
    }
  }
  return b;
}
Exemplo n.º 5
0
void GVSkeletonGraph::clearNodes(){
    setlocale(LC_NUMERIC,"en_US.UTF-8"); // Débug séparateur de décimales en version française
	QList<QString> keys = _nodes.keys();
	for(int i=0;i<keys.size();++i){
		removeNode(keys.at(i));
	}
}
Exemplo n.º 6
0
/* 
*  Internal function to remove a node from a tree - used by assert() method
*
*  Returns:
*    0 - don't remove the parent node
*    1 - consider removing the parent node (if no value or root)
*    2 - remove the parent node (even if it has a value and/or root)
*/
static int removeNode(nbCELL context,BTree *tree,BTreeNode **nodeP,nbSET *argSetP){
  NB_TreePath path;
  BTreeNode *node=*nodeP;
  nbCELL argCell;
  int code=1;

  argCell=nbListGetCellValue(context,argSetP);
  if(argCell==NULL){
    if(node==NULL) return(3);  // the perfect match - nothing to nothing
    code=2; 
    return(2);                   //
    }
  else{
    if(node==NULL) return(0);  // can't match to empty tree
    if(tree->options&BTREE_OPTION_ORDER) 
      node=(BTreeNode *)nbTreeLocateValue(&path,argCell,(NB_TreeNode **)nodeP,treeCompare,context);
    else node=nbTreeLocate(&path,argCell,(NB_TreeNode **)nodeP);   
    nbCellDrop(context,argCell);
    if(node==NULL) return(0);          // didn't find argument
    switch(removeNode(context,tree,&node->root,argSetP)){
      case 0: return(0);
      case 1:
        if(node->root!=NULL) return(0);  // still need this node
        break;
      // For case 2 we just fall thru to unlink the node
      }
    }
  if(node->root!=NULL) return(0);  
  nbTreeRemove(&path);  // Remove node from binary search tree
  if(node->bnode.key!=NULL) node->bnode.key=nbCellDrop(context,(nbCELL)node->bnode.key);  // release key
  //if(node->root!=NULL) node->root =removeTree(context,tree,node->root);
  nbFree(node,sizeof(BTreeNode));
  return(code);
  }
Exemplo n.º 7
0
int S_removeUnusedVariables(struct Node *t) {
  if (t == NULL)
    return 0;
  
  if (t->tag == TASSIGN) {
    char *name = t->children->iname;
    if (variableIsUsed(name) == 0) {
      fprintf(warn, "Removing Variable Assignment: %s\n", name);
      if (t->parent != NULL) {
        if (t->parent->children == t) {
          t->parent->children = t->next;
        }
      }
      removeNode(t);
      return 1;
    } else {
      registerAllUsedVariables(t->children->next);
      return 0;
    }
  }else if (t->tag == TCOMBINE) {
    struct Node *pntr = t->children;
    struct Node *tmp = NULL;
    if (pntr == NULL) {
      return 0;
    }
    while (pntr->next != NULL) {
      pntr = pntr->next;
    }
    while (pntr != NULL) {
      tmp = pntr;
      pntr = pntr->previous;
      S_removeUnusedVariables(tmp);
    }
    if (t->children == NULL) {
      removeNode(t);
      return 1;
    }
  } else {
    struct Node *tmp = t->children;
    while (tmp != NULL) {
      registerAllUsedVariables(tmp);
      tmp = tmp->next;
    }
    return 0;
  }
  return 0;
}
Exemplo n.º 8
0
void main()
{
	cout<<"请输入有向图的节点,以-1,-1结束:"<<endl;
	int i,j;
	while(true)
	{
		cin>>i>>j;
		if(i==-1 && j==-1) break;
		if(i<0  || j<0)
		{
			cout<<"输入错误"<<endl;
			exit(1);
		}
		arc[i][j] = 1;
		cout<<endl;
	}
	cout<<"节点数(1~"<<MAX_NODE<<"):"<<endl;
	cin>>n;
	if(n<1 || n>MAX_NODE)
	{
		cout<<"错误,节点数必须是在1到"<<MAX_NODE<<"之间的数"<<endl;
		exit(1);
	}

	cout<<"输出邻接矩阵如下:"<<endl;
	showMGraph();

	//进行拓扑排序
	while(true)
	{
		//假设所有剩余的节点都没有入度
		bool flag = true;

		for(int i=0; i<n; i++)
		{
			//如果是已被移除或者存在入度的节点
			if((arc[i][i] == -1) || hasInRoad(i)) continue;

			//发现了一个入度,假设不成立
			flag = false;

			//该节点没有入度
			list[index++] = i;
			removeNode(i);

			//所有节点都已经排序
			if(index>=n)
			{
				showList();
				return;
			}
		}
		if(flag)
		{
			cout<<"该有向图含有环."<<endl;
			exit(2);
		}
	}
}
Exemplo n.º 9
0
ScrollingNodeID ScrollingStateTree::attachNode(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID)
{
    ASSERT(newNodeID);

    if (ScrollingStateNode* node = stateNodeForID(newNodeID)) {
        ScrollingStateNode* parent = stateNodeForID(parentID);
        if (!parent)
            return newNodeID;
        if (node->parent() == parent)
            return newNodeID;

        // The node is being re-parented. To do that, we'll remove it, and then re-create a new node.
        removeNode(node);
    }

    ScrollingStateNode* newNode = 0;
    if (!parentID) {
        // If we're resetting the root node, we should clear the HashMap and destroy the current children.
        clear();

        setRootStateNode(ScrollingStateFrameScrollingNode::create(*this, newNodeID));
        newNode = rootStateNode();
        m_hasNewRootStateNode = true;
    } else {
        ScrollingStateNode* parent = stateNodeForID(parentID);
        if (!parent)
            return 0;

        switch (nodeType) {
        case FixedNode: {
            OwnPtr<ScrollingStateFixedNode> fixedNode = ScrollingStateFixedNode::create(*this, newNodeID);
            newNode = fixedNode.get();
            parent->appendChild(fixedNode.release());
            break;
        }
        case StickyNode: {
            OwnPtr<ScrollingStateStickyNode> stickyNode = ScrollingStateStickyNode::create(*this, newNodeID);
            newNode = stickyNode.get();
            parent->appendChild(stickyNode.release());
            break;
        }
        case FrameScrollingNode: {
            OwnPtr<ScrollingStateFrameScrollingNode> scrollingNode = ScrollingStateFrameScrollingNode::create(*this, newNodeID);
            newNode = scrollingNode.get();
            parent->appendChild(scrollingNode.release());
            break;
        }
        case OverflowScrollingNode: {
            OwnPtr<ScrollingStateOverflowScrollingNode> scrollingNode = ScrollingStateOverflowScrollingNode::create(*this, newNodeID);
            newNode = scrollingNode.get();
            parent->appendChild(scrollingNode.release());
            break;
        }
        }
    }

    m_stateNodeMap.set(newNodeID, newNode);
    return newNodeID;
}
Exemplo n.º 10
0
static void Cut(PQueue *h, PQueueElement *x, PQueueElement *y)
{
    removeNode(x);
    y->degree--;
    insertrootlist(h, x);
    x->Parent = NULL;
    x->Mark = 0;
}
Exemplo n.º 11
0
/*
 * updates the vertex list when and edge is removed so that
 * the vertex list contains the proper new edges for the 
 * corresponding vertices
 */
void removeEdgeFromVertices(vertexSet * head, int id)
{
  while(head!=NULL)
  {
    removeNode(&head->edges, id);
    head = head->nextVertex;
  }
}
Exemplo n.º 12
0
void CDoubleLinkedList::removeAllNodes()
{	
  while ( NULL != m_pHead ) {
    removeNode( m_pTail );
  }	
  
  Init();
};
Exemplo n.º 13
0
void GVSkeletonGraph::clearNodes(){
    	setlocale(LC_NUMERIC,"en_US.UTF-8");
	
	QList<QString> keys = _nodes.keys();
	for(int i=0;i<keys.size();++i){
		removeNode(keys.at(i));
	}
}
Exemplo n.º 14
0
void SwitchNode::clearNodes() {
	while (nodes->size() > 0) {
		removeNode( nodes->size() - 1 );
	}
	setDefaultNode( NULL );
	clearAnchors();
	clearPorts();
}
Exemplo n.º 15
0
void 
test__remove_node_not_present(void **state)
{   
    initializeHashTable(100);
	int result = removeNode(101);
    assert_true(result == -1);
	cleanUpTable();
}
Exemplo n.º 16
0
bool NodeTree::removeNode(const std::string& nodeName)
{
    auto iter = _nodeNameToNodeID.find(nodeName);
    if(iter == _nodeNameToNodeID.end())
        return false;

    return removeNode(iter->second);
}
Exemplo n.º 17
0
void ProcessorGraph::removeProcessor(GenericProcessor* processor)
{

    std::cout << "Removing processor with ID " << processor->getNodeId() << std::endl;

    removeNode(processor->getNodeId());

}
Exemplo n.º 18
0
IZ_BOOL AnimationStateMachine::removeNode(const char* name)
{
    auto node = getNode(name);

    auto ret = removeNode(node);

    return ret;
}
Exemplo n.º 19
0
void MythGenericTree::deleteNode(MythGenericTree *child)
{
    if (!child)
        return;

    removeNode(child);
    delete child;
}
Exemplo n.º 20
0
void MyThreadYield(void)
{
	//printf("MyThreadYield: START ... curr_th = %d , parent_th = %d\n", curr_th->tid, curr_th->pid);
		
	/*if(0!=getcontext(&curr_context))l
	{
		//printf("MyThreadYield : getcontext error... \n");
	}*/
	
	if(front==NULL)
	{
		//printf("No pending ready thread, invoking thread = %d , will continue to run \n", curr_th->tid);
		return;
	}
	
	ucontext_t new_cnxt;
	struct node * new_th=pop_q();
	
	if(new_th == NULL)
	{
		//printf("MyThreadYield: ready queue is empty...continue running this thread... \n");
		return;	
	}
	
	new_cnxt=new_th->cnxt;
	
	//printf("Inserting saved context to the queue : GetContext removed... \n");
	struct node * tmp=insert_q(curr_th->cnxt,curr_th->tid,curr_th->pid,curr_th->join_th,curr_th->join_th_rear);

	int old_th=curr_th->tid;
	int old_pr=curr_th->pid;
	ucontext_t old_cnxt=curr_th->cnxt;
	struct join_list *old_jfront=curr_th->join_th;
	struct join_list *old_jrear=curr_th->join_th_rear;
	curr_th->tid=new_th->tid;
	curr_th->pid=new_th->pid;
	curr_th->cnxt=new_th->cnxt;
	curr_th->join_th=new_th->join_th;
	curr_th->join_th_rear=new_th->join_th_rear;
	

	//printf("MyThreadYield: swap context from thread : %d ,to first ready thread : %d ... \n",tmp->tid,curr_th->tid);
	//printf("MyThreadYield: swap context from =%d , to  = %d  which is also same as new_cnxt=%d\n ",tmp->cnxt,curr_th->cnxt,new_cnxt);
	

	if(swapcontext(&(tmp->cnxt),&(new_th->cnxt))==-1)
	{
		curr_th->tid=old_th;
		curr_th->pid=old_pr;
		curr_th->cnxt=old_cnxt;
		curr_th->join_th=old_jfront;
		curr_th->join_th_rear=old_jrear;
		removeNode(curr_th->tid);
		//printf("MyThreadYield: swapcontext error...\n");	
	}

	//printf("MyThreadYield: EXIT... \n\n\n");
}
Exemplo n.º 21
0
Arquivo: dl61.c Projeto: jleffler/soq
int main(void)
{
    Node *head = 0;
    head = addNodeAtHead(head, 23);
    head = addNodeAtHead(head, 43);
    head = addNodeAtHead(head, 73);
    head = addNodeAtHead(head, 13);
    head = addNodeAtHead(head, 33);
    dumpList("Completed", head);

    head = removeNode(head, 33);
    dumpList("Remove 33", head);
    head = removeNode(head, 23);
    dumpList("Remove 23", head);
    head = removeNode(head, 13);
    dumpList("Remove 13", head);
    head = removeNode(head, 34);
    dumpList("Remove 34", head);
    head = removeNode(head, 43);
    dumpList("Remove 43", head);
    head = removeNode(head, 73);
    dumpList("Remove 73", head);
    head = removeNode(head, 37);
    dumpList("Remove 37", head);

    return 0;
}
Exemplo n.º 22
0
static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) {
  Node *kw = nextSibling(nameobj);
  List *matchlist = 0;
  while (kw) {
    Node *next = nextSibling(kw);
    String *kname = Getattr(kw, "name");
    char *ckey = kname ? Char(kname) : 0;
    if (ckey) {
      const char **rkey;
      int isnotmatch = 0;
      int isregexmatch = 0;
      if ((strncmp(ckey, "match", 5) == 0)
	  || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0))
	  || (isregexmatch = (strncmp(ckey, "regexmatch", 10) == 0))
	  || (isnotmatch = isregexmatch = (strncmp(ckey, "notregexmatch", 13) == 0))) {
	Hash *mi = NewHash();
	List *attrlist = Swig_make_attrlist(ckey);
	if (!matchlist)
	  matchlist = NewList();
	Setattr(mi, "value", Getattr(kw, "value"));
	Setattr(mi, "attrlist", attrlist);
	if (isnotmatch)
	  SetFlag(mi, "notmatch");
	if (isregexmatch)
	  SetFlag(mi, "regexmatch");
	Delete(attrlist);
	Append(matchlist, mi);
	Delete(mi);
	removeNode(kw);
      } else {
	for (rkey = keys; *rkey != 0; ++rkey) {
	  if (strcmp(ckey, *rkey) == 0) {
	    Setattr(nameobj, *rkey, Getattr(kw, "value"));
	    removeNode(kw);
	  }
	}
      }
    }
    kw = next;
  }
  if (matchlist) {
    Setattr(nameobj, "matchlist", matchlist);
    Delete(matchlist);
  }
}
Exemplo n.º 23
0
static void removerootlist(PQueue *h, PQueueElement *x)
{
    if (x->Left == x)
        h->Root = NULL;
    else {
        h->Root = removeNode(x);
        x->Key = INT_MIN;
    }
}
Exemplo n.º 24
0
/****************************************************************************
**
** Copyright (C) 2014
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include <QMessageBox>
#include "node_compound.h"
#include "node_editorwidget.h"
#include "node_port.h"

namespace Magus
{
    //****************************************************************************/
    QtCompoundNode::QtCompoundNode(QString title, QGraphicsItem* parent) : QtNode(title, parent)
    {
        setData(NODE_KEY_GRAPHIC_ITEM_SUBTYPE, QVariant(NODE_VALUE_SUBTYPE_COMPOUND));
        mAutoSize = false;
    }

    //****************************************************************************/
    QtCompoundNode::~QtCompoundNode(void)
    {
    }

    //****************************************************************************/
    void QtCompoundNode::_prepareDelete(void)
    {
        // First release the nodes
        QtCompoundNode* compound;
        foreach(QtNode* node, mNodeList)
            removeNode(node);

        mNodeList.clear();
    }
Exemplo n.º 25
0
GList *
setPertNodesPosition()
{
	GList *l;
	GList *ll;
	GList *nodesuccessors;

	nbCols = 0;
	GList *l3;
	for(l3 = pertnodes;l3;l3=l3->next)
			{
		        g_object_set(G_OBJECT(l3->data),"col",-1,"row",-1,"seted",FALSE,NULL);
			}

	for(l3 = pertnodes;l3;l3=l3->next)
		{
			gint a = planner_pertchart_node_get_col (l3->data);
			gint b = planner_pertchart_node_get_row (l3->data);

		}

	l=pertnodes;
	while(l)
	{

	   gboolean set = planner_pertchart_node_get_seted(l->data);

       if(!set && isZeroPosition(l->data))
       {
    		   addNode(0,l->data);
    		   l=pertnodes;
    	}


       l = l->next;
	}
	gint nodecol = 0;
	nodesuccessors = getPertNodeSuccessorsInOneCol(nodecol);
	while(nodesuccessors != NULL)
	{
		for(ll=nodesuccessors;ll;ll=ll->next)
		{
			gboolean set = planner_pertchart_node_get_seted(ll->data);
			if(set)
			{
				removeNode(ll->data);
			}
			g_printf("the next col of nodesuccessors is%d",nodecol+1);
			addNode(nodecol + 1,ll->data);
		}
		nodecol++;

		nodesuccessors = getPertNodeSuccessorsInOneCol(nodecol);
	}

	return pertnodes;
}
Exemplo n.º 26
0
void VCProject::writeConfigurationItemDefinitions(pugi::xml_node& node) const
{
  for (auto configKV : m_configurations) {
    configKV.second->writeItemDefinitions(node);
  }

  // The node is a bookmark. Remove it.
  removeNode(node);
}
Exemplo n.º 27
0
void testLL() {
    node* head = NULL;
    int vals[20] = {2,2,2,4,4,2,6,2,4,4,31,37,9,6,4,5,2,2,2,4};
    // Initialize:
    int i;
    for (i=0; i < 20; i++) {
        insertNode(&head, vals[i]);
    }
    
    // Get stats
    printf("Size: %d, Index of 6: %d\n", countNodes(head), searchLL(head, 6));
    printLL(head);
    removeNode(&head, 2);
    printLL(head);
    removeNode(&head, 4);
    printLL(head);
    printf("Size: %d, Index of 6: %d\n", countNodes(head), searchLL(head, 6));
}
Exemplo n.º 28
0
Arquivo: list.c Projeto: nighca/c
Node* pop(List* list){
    Node* n = list->tail;

    if(n != NULL){
        removeNode(list, n);
    }

    return n;
}
Exemplo n.º 29
0
Arquivo: list.c Projeto: nighca/c
Node* shift(List* list){
    Node* n = list->head;

    if(n != NULL){
        removeNode(list, n);
    }

    return n;
}
Exemplo n.º 30
0
	FPTRLIST_INLINE bool FPtrList::FPtrListPrivate::remove(int nIndex)
	{
		if (!moveTo(nIndex))
		{
			return false;
		}

		return removeNode(m_pCursor);
	}