void DSBBranch::setMainConnections(QList<DSBNode*> own) { for (int i = 0; i < own.size(); i++) { DSBNode *n = own.at(i); DSBReaction *reac = dynamic_cast<DSBReaction*>(n); DSBClone *cl = dynamic_cast<DSBClone*>(n); if (reac) { // predecessor n = getPredecessor(reac); if (n) { DSBClone *c = dynamic_cast<DSBClone*>(n); assert(c); reac->setMainInput(c); } // successor n = getSuccessor(reac); if (n) { DSBClone *c = dynamic_cast<DSBClone*>(n); assert(c); reac->setMainOutput(c); } } else if (cl) { DSBFork *fork = cl->getFork(); if (fork) { // predecessor n = getPredecessor(cl); if (n) { DSBReaction *r = dynamic_cast<DSBReaction*>(n); assert(r); fork->setMainInput(r); } // successor n = getSuccessor(cl); if (n) { DSBReaction *r = dynamic_cast<DSBReaction*>(n); assert(r); fork->setMainOutput(r); } } } else { qDebug() << "ERROR: Found Node which was neither Clone nor Reaction: " << n; } } }
/** * @brief Skips empty statements in @a stmt. * * @param[in] stmts Sequence of statements where empty statements should be * skipped. * * @return First non-empty statement in @a stmts. * * If there is no non-empty statement in @a stmts, the null pointer is returned. */ ShPtr<Statement> skipEmptyStmts(ShPtr<Statement> stmts) { auto currStmt = stmts; while (isa<EmptyStmt>(currStmt)) { currStmt = currStmt->getSuccessor(); } return currStmt; }
Node *removeAt(size_t index, Node **toDelete) { assert(index < size); if (this == &emptyLeafNode) throw "Illegal argument"; size_t leftSize = left->size; if (index < leftSize) left = left->removeAt(index, toDelete); else if (index > leftSize) right = right->removeAt(index - leftSize - 1, toDelete); else if (left == &emptyLeafNode && right == &emptyLeafNode) { assert(*toDelete == NULL); *toDelete = this; return &emptyLeafNode; } else if (left != &emptyLeafNode && right == &emptyLeafNode) { Node *result = left; left = NULL; assert(*toDelete == NULL); *toDelete = this; return result; } else if (left == &emptyLeafNode && right != &emptyLeafNode) { Node *result = right; right = NULL; assert(*toDelete == NULL); *toDelete = this; return result; } else { // We can remove the successor or the predecessor std::swap(value, getSuccessor()); right = right->removeAt(0, toDelete); } recalculate(); return balance(); }
SimpleInterval* IntervalTree::deleteNode(IntervalTreeNode* z) { IntervalTreeNode* y; IntervalTreeNode* x; SimpleInterval* node_to_delete = z->stored_interval; y= ((z->left == nil) || (z->right == nil)) ? z : getSuccessor(z); x= (y->left == nil) ? y->right : y->left; if(root == (x->parent = y->parent)) { root->left = x; } else { if(y == y->parent->left) { y->parent->left = x; } else { y->parent->right = x; } } /// @brief y should not be nil in this case /// y is the node to splice out and x is its child if(y != z) { y->max_high = -std::numeric_limits<double>::max(); y->left = z->left; y->right = z->right; y->parent = z->parent; z->left->parent = z->right->parent = y; if(z == z->parent->left) z->parent->left = y; else z->parent->right = y; fixupMaxHigh(x->parent); if(!(y->red)) { y->red = z->red; deleteFixup(x); } else y->red = z->red; delete z; } else { fixupMaxHigh(x->parent); if(!(y->red)) deleteFixup(x); delete y; } return node_to_delete; }
/** This function marks that the successor n should be used to reach this * node. It then recursively (depth first) does the same for all its * successors. Depth-first * \param n The successor which should be used in m_path_node to reach * this node. * \param path_to_node The path-to-node data structure of the node for * which the paths are currently determined. */ void GraphNode::markAllSuccessorsToUse(unsigned int n, PathToNodeVector *path_to_node) { // End recursion if the path to this node has already been found. if( (*path_to_node)[m_node_index] >-1) return; (*path_to_node)[m_node_index] = n; for(unsigned int i=0; i<getNumberOfSuccessors(); i++) { GraphNode &gn = QuadGraph::get()->getNode(getSuccessor(i)); gn.markAllSuccessorsToUse(n, path_to_node); } } // markAllSuccesorsToUse
/** * @brief Adds @a var as a new local variable of @a func, possibly with an * initializer @a init. * * An advatage of using this function over manually adding @a var to @a func is * that this function also creates a VarDefStmt at the beginning of @a func, and * places it in a proper place so that all VarDefStmts at the beginning of @a * func are sorted alphabetically. * * If @a var is already a local function of @a func, this function does nothing. * * @par Preconditions * - @a func is a definition, not a declaration */ void addLocalVarToFunc(ShPtr<Variable> var, ShPtr<Function> func, ShPtr<Expression> init) { PRECONDITION(func->isDefinition(), "it has to be a definition"); if (func->hasLocalVar(var)) { return; } func->addLocalVar(var); // Insert a variable-defining statement to a proper position at the // beginning of the function's body. // First, we find a proper position... auto stmt = func->getBody(); while (auto varDefStmt = cast<VarDefStmt>(stmt)) { if (varDefStmt->getVar()->getName() > var->getName() || !stmt->getSuccessor()) { break; } stmt = stmt->getSuccessor(); } // ...then, we place a VarDefStmt of var into that position. stmt->prependStatement(VarDefStmt::create(var, init)); }
/** If this node has more than one successor, it will set up a vector that * contains the direction to use when a certain graph node X should be * reached. */ void GraphNode::setupPathsToNode() { if(m_successor_nodes.size()<2) return; const unsigned int num_nodes = QuadGraph::get()->getNumNodes(); m_path_to_node.resize(num_nodes); // Initialise each graph node with -1, indicating that // it hasn't been reached yet. for(unsigned int i=0; i<num_nodes; i++) m_path_to_node[i] = -1; // Indicate that this node can be reached from this node by following // successor 0 - just a dummy value that might only be used during the // recursion below. m_path_to_node[m_node_index] = 0; // A simple depth first search is used to determine which successor to // use to reach a certain graph node. Using Dijkstra's algorithm would // give the shortest way to reach a certain node, but the shortest way // might involve some shortcuts which are hidden, and should therefore // not be used. for(unsigned int i=0; i<getNumberOfSuccessors(); i++) { GraphNode &gn = QuadGraph::get()->getNode(getSuccessor(i)); gn.markAllSuccessorsToUse(i, &m_path_to_node); } #ifdef DEBUG for(unsigned int i=0; i<m_path_to_node.size(); i++) { if(m_path_to_node[i]==-1) printf("[WARNING] No path to node %d found on graph node %d.\n", i, m_node_index); } #endif } // setupPathsToNode
int FingerTable::toString(char **buf , unsigned int &length) { /**/ char *buffer = new char[4000] ; if (buffer==NULL) return -1; char *message = buffer ; sprintf(message,"**********FINGER TABLE**********") ; message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; for(int i = 0 ; i < getTableLength() ; i++) { sprintf (message, "finger[%d]: node:%d start:%d interval:%d~%d", i+1, getFinger(i+1)->node.GetId() , getFinger(i+1)->start.GetId() , getFinger(i+1)->interval[0].GetId() , getFinger(i+1)->interval[1].GetId() ); message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; } sprintf(message,"**********SUCC LIST**********") ; message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; for(i = 0 ; i < getSuccNum() ; i++) { sprintf (message, "SUCCLIST[%d]: id:%d ip:%s", i, getSuccessor(i).GetId() , getSuccessor(i).GetAddress() ); message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; } sprintf(message,"\r\n**********PREDECESSOR**********") ; message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; sprintf (message, "PREDECESSOR: id:%d ip:%s", getPredecessor().GetId() , getPredecessor().GetAddress() ); message = message + strlen (message); strncpy (message, "\r\n\0", 2); message = message + 2; strncpy(message,"\0",1) ; *buf = buffer ; length = strlen(buffer) ; return 0 ; }