void QElement::readData(){ for(int i = 0; i < getNodeCount(); ++i){ for(int j = 0; j < getNodeCount(); j++){ scanf("%d",&mat[i][j]); if (i == j) mat[i][j] = INF; } } }
int KDNode::getNodeCount(KDNode* node){ int count = 0; if(node->left != NULL){ count = getNodeCount(node->left); } if(node->right != NULL){ count += getNodeCount(node->right); } return count+1; }
std::vector<int> QElement::expandNode(){ std::vector<bool> already(getNodeCount(),false); std::vector<int> retVal; for(int i = 0; i < (int) visited.size(); ++i){ already[visited[i]] = true; } for(int i = 0; i < getNodeCount(); ++i){ if (!already[i]) retVal.push_back(i); } return retVal; }
void SimplePathGraph::drawDebugShapes ( DebugShapeRenderer * renderer ) const { UNREF(renderer); #ifdef _DEBUG if(renderer == NULL) return; if( m_debugLines ) renderer->drawLineList( *m_debugLines, VectorArgb::solidYellow ); int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode const * node = getNode(i); // if(node->isPortalAdjacent()) // { // renderer->setColor( VectorArgb::solidMagenta ); // } // else { renderer->setColor( VectorArgb::solidCyan ); } Vector center = node->getPosition_p() + Vector(0.0f,0.5f,0.0f); renderer->drawSphere( Sphere(center,0.2f) ); } #endif }
int main() { // Initialize the root Node *root = NULL; int insertElements(Node **root,int data); int printElements(Node *root); int getMaxDepth(Node *root,int parentLevel); int getNodeCount(Node *root); int hasPathSum(Node *root,int sumValue,int parentSumVal); int printPath(Node *root); int numElements; printf("Please enter the number of elements to be inserted\n"); scanf("%d",&numElements); if (numElements > MAXELEMENTS) { printf("Exceeded total num of elements allowed\n"); return 0; } // Input elements into BST for (int i=1;i<=numElements;i++) { int data; printf("Enter node data \n"); scanf("%d",&data); if (!insertElements(&root,data)) { printf("Unable to insert element\n"); return 0; } } // print BST elements if (!printElements(root)) { printf("Unable to print elements\n"); return 0; } printf("The max depth of the tree %d \n",getMaxDepth(root,100)); printf("Number of nodes in the tree %d \n",getNodeCount(root)); int sumVal; printf("Enter the sum value \n"); scanf("%d",&sumVal); if (hasPathSum(root,sumVal,100)) { printf("sum of at least one of the path is %d\n",sumVal); } else { printf("There is no path with sum %d\n",sumVal); } return 1; }
int PathGraph::findNearestNode ( PathNodeType searchType, Vector const & position_p ) const { int minNode = -1; float minDist2 = REAL_MAX; int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode const * node = getNode(i); if(node == NULL) continue; if(getEdgeCount(i) == 0) continue; PathNodeType type = node->getType(); if(type != searchType) continue; float dist2 = position_p.magnitudeBetweenSquared(node->getPosition_p()); if(dist2 < minDist2) { minNode = i; minDist2 = dist2; } } return minNode; }
int PathGraph::findEntrance ( int key ) const { int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode const * node = getNode(i); if(node == NULL) continue; if(getEdgeCount(i) == 0) continue; PathNodeType type = node->getType(); if((type == PNT_CellPortal) || (type == PNT_BuildingEntrance) || (type == PNT_CityEntrance)) { if(node->getKey() == key) { return i; } } } return -1; }
float* mbChargeLattice::getCharges() { mbChargeNode node; deallocChargeReturn(); chargeReturn = new float[getNodeCount() * 4]; int i, index; for (i = 0; i < getNodeCount(); i++) { node = chargeNodes[i]; index = i * 4; chargeReturn[index] = node.x; chargeReturn[index + 1] = node.y; chargeReturn[index + 2] = node.z; chargeReturn[index + 3] = node.charge; }; return chargeReturn; };
int QElement::reduceMatrix(int u,int v){ int retVal = 0; for(int i = 0; i < getNodeCount(); i++){ for(int j = 0; j < getNodeCount(); j++){ if (i == u || j == v) mat[i][j] = INF; } } for(int i = 0; i < getNodeCount(); ++i){ int vMin = this->getValMinRow(i); this->reduceRow(i,vMin); if (vMin != INF) retVal += vMin; } for(int j = 0; j < getNodeCount(); ++j){ int vMin = this->getValMinCol(j); this->reduceCol(j,vMin); if (vMin != INF) retVal += vMin; } return retVal; }
int QElement::reduceRow(int r,int val){ int retVal = 0; for(int j = 0; j < getNodeCount(); ++j){ if (mat[r][j] != INF){ retVal += (mat[r][j] - val); mat[r][j] -= val; } } return retVal; }
// Test void printAllNode(Node* head) { Node* node = head; int Count = getNodeCount(head); while( node != NULL && Count > 0 ) { printNode(node); node = node->next; Count--; } }
int QElement::getValMinRow(int r){ int minRes = INF; int idxMinRes = -1; for(int i = 0; i < getNodeCount(); ++i){ if (mat[r][i] != INF && mat[r][i] < minRes){ idxMinRes = i; minRes = mat[r][i]; } } return minRes; }
int QElement::getValMinCol(int c){ int minRes = INF; int idxMinRes = -1; for(int i = 0; i < getNodeCount(); ++i){ if (mat[i][c] != INF && mat[i][c] < minRes){ idxMinRes = i; minRes = mat[i][c]; } } return minRes; }
int QElement::reduceCol(int c,int val){ int retVal = 0; for(int i = 0; i < getNodeCount(); i++){ if (mat[i][c] != INF){ retVal += (mat[i][c] - val); mat[i][c] -= val; } } return retVal; }
int getNodeCount(Node *root) { static int nodeCount = 0; if (root) { ++nodeCount; if (root->leftChild) { getNodeCount(root->leftChild); } if (root->rightChild) { getNodeCount(root->rightChild); } } return nodeCount; }
std::string Node::getRawData(bool includeName) const { std::string s, v = data(); bool hasV = find_if(v.begin(), v.end(), std::not1(std::ptr_fun(isspace))) != v.end(); if (includeName) { s += "<" + name(); unsigned int attCnt = 0; for( unsigned int i = 0; i < getNodeCount(); ++i ) { Node *node = getNode( i ); if( node->nodeType() == Attribute) { s += " " + node->name() + "='"+ node->asString() + "'"; attCnt++; } } if (attCnt == getNodeCount()) // have not elements { if (!hasV) s += "/>"; else s += ">" + v + "</" + name() + ">\r\n"; return s; } else { s += ">\r\n"; if (hasV) s += v + "\r\n"; } } for( unsigned int i = 0; i < getNodeCount(); ++i ) { Node *node = getNode( i ); if( node->nodeType() == Element) s += node->getRawData(); } if (includeName) s += "</" + name() + ">\r\n"; return s; }
bool Node::lookupAttribute( const std::string &name, std::string &data ) const { for( unsigned int i = 0; i < getNodeCount(); ++i ) { Node *node = getNode( i ); if( node->nodeType() != Attribute || node->name() != name ) continue; data = node->data(); return true; } return false; }
void Graph::printGraph() { unsigned int retval = -1; for(std::map<int, graphPoint* >::iterator it = graphNodes.begin(); it != graphNodes.end(); ++it) { it->second->printGraphPoint(); } std::cout << "TOTAL NODES: " << getNodeCount() << "\tTOTAL EDGES: " << getEdgeCount() << "\n" << std::endl; }
/** * @brief Send statistics to an output stream. */ void print( std::ostream& out = std::cout ) { out << "NodeCount=" << getNodeCount() << std::endl; NodeTypeIterator iter, iter_end; for( boost::tie( iter, iter_end ) = getNodeTypeIterators(); iter != iter_end; iter++ ) { out << "(" << iter->first << ", " << iter->second << ")" << std::endl; } }
nfBool CMesh::checkSanity() { nfUint32 nIdx, j; nfUint32 nNodeCount = getNodeCount(); nfUint32 nFaceCount = getFaceCount(); nfUint32 nBeamCount = getBeamCount(); // max 2 billion Nodes/Faces if (nNodeCount > NMR_MESH_MAXNODECOUNT) return false; if (nFaceCount > NMR_MESH_MAXFACECOUNT) return false; if (nBeamCount > NMR_MESH_MAXBEAMCOUNT) return false; for (nIdx = 0; nIdx < nNodeCount; nIdx++) { MESHNODE * node = getNode(nIdx); if (node->m_index != (nfInt32) nIdx) return false; for (j = 0; j < 3; j++) if (fabs(node->m_position.m_fields[j]) > NMR_MESH_MAXCOORDINATE) return false; } for (nIdx = 0; nIdx < nFaceCount; nIdx++) { MESHFACE * face = getFace(nIdx); for (j = 0; j < 3; j++) if ((face->m_nodeindices[j] < 0) || (((nfUint32)face->m_nodeindices[j]) >= nNodeCount)) return false; if ((face->m_nodeindices[0] == face->m_nodeindices[1]) || (face->m_nodeindices[0] == face->m_nodeindices[2]) || (face->m_nodeindices[1] == face->m_nodeindices[2])) return false; } for (nIdx = 0; nIdx < nBeamCount; nIdx++) { MESHBEAM * beam = getBeam(nIdx); for (j = 0; j < 2; j++) if ((beam->m_nodeindices[j] < 0) || (((nfUint32)beam->m_nodeindices[j]) >= nNodeCount)) return false; if (beam->m_nodeindices[0] == beam->m_nodeindices[1]) return false; } return true; }
void CNodeMgr::sortNodeList(int p_type) { /* 外で排他かけること!! */ int count = getNodeCount(); if (count > 1) { CNode* data = new CNode[count]; for (int i = 0; i < count; i++) data[i] = *getNode(i); assert(p_type < SORTTYPECOUNT); qsort(data, count, sizeof(CNode), (int(*)(const void*, const void*))g_sortfunc[p_type]); for (int i = 0; i < count; i++) m_nodeList.set(i, data[i]); delete[] data; } }
int PathGraph::findNode ( PathNodeType type, int key ) const { int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode const * node = getNode(i); if(getEdgeCount(i) == 0) continue; if((node != NULL) && (node->getType() == type) && (node->getKey() == key)) { return i; } } return -1; }
bool Node::lookupAttribute( const std::string &name, int &data ) const { for( unsigned int i = 0; i < getNodeCount(); ++i ) { Node *node = getNode( i ); if( node->nodeType() != Attribute || node->name() != name ) continue; if( node->data().find( "0x" ) == 0 ) { data = strtol( node->data().substr( 2, node->data().length() - 2 ).c_str(), 0, 16 ); } else data = atoi( node->data().c_str() ); return true; } return false; }
void PathGraph::findNodesInRange ( Vector const & position_p, float range, PathNodeList & results ) const { float range2 = range * range; int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode const * node = getNode(i); if(node == NULL) continue; if(getEdgeCount(i) == 0) continue; float dist2 = position_p.magnitudeBetweenSquared(node->getPosition_p()); if(dist2 < range2) { results.push_back( const_cast<PathNode*>(node) ); } } }
_Ret_notnull_ MESHNODE * CMesh::addNode(_In_ const NVEC3 vPosition) { MESHNODE * pNode; nfUint32 j; // Check Position Validity for (j = 0; j < 3; j++) if (fabs(vPosition.m_fields[j]) > NMR_MESH_MAXCOORDINATE) throw CNMRException(NMR_ERROR_INVALIDCOORDINATES); // Check Node Quota nfUint32 nNodeCount = getNodeCount(); if (nNodeCount > NMR_MESH_MAXNODECOUNT) throw CNMRException(NMR_ERROR_TOOMANYNODES); // Allocate Data nfUint32 nNewIndex; pNode = m_Nodes.allocData(nNewIndex); pNode->m_index = nNewIndex; pNode->m_position = vPosition; return pNode; }
CC3Node* CC3NodePuncturingVisitor::getClosestPuncturedNode() { return getNodeCount() > 0 ? getPuncturedNodeAt( 0 ) : NULL; }
static int runUpgrade_Half(NDBT_Context* ctx, NDBT_Step* step) { // Assuming 2 replicas AtrtClient atrt; const bool waitNode = ctx->getProperty("WaitNode", Uint32(0)) != 0; const bool event = ctx->getProperty("CreateDropEvent", Uint32(0)) != 0; const char * args = ""; if (ctx->getProperty("KeepFS", Uint32(0)) != 0) { args = "--initial=0"; } NodeSet mgmdNodeSet = (NodeSet) ctx->getProperty("MgmdNodeSet", Uint32(0)); NodeSet ndbdNodeSet = (NodeSet) ctx->getProperty("NdbdNodeSet", Uint32(0)); SqlResultSet clusters; if (!atrt.getClusters(clusters)) return NDBT_FAILED; while (clusters.next()) { uint clusterId= clusters.columnAsInt("id"); SqlResultSet tmp_result; if (!atrt.getConnectString(clusterId, tmp_result)) return NDBT_FAILED; NdbRestarter restarter(tmp_result.column("connectstring")); restarter.setReconnect(true); // Restarting mgmd g_err << "Cluster '" << clusters.column("name") << "@" << tmp_result.column("connectstring") << "'" << endl; if(restarter.waitClusterStarted()) return NDBT_FAILED; // Restart ndb_mgmd(s) SqlResultSet mgmds; if (!atrt.getMgmds(clusterId, mgmds)) return NDBT_FAILED; uint mgmdCount = mgmds.numRows(); uint restartCount = getNodeCount(mgmdNodeSet, mgmdCount); ndbout << "Restarting " << restartCount << " of " << mgmdCount << " mgmds" << endl; while (mgmds.next() && restartCount --) { ndbout << "Restart mgmd" << mgmds.columnAsInt("node_id") << endl; if (!atrt.changeVersion(mgmds.columnAsInt("id"), "")) return NDBT_FAILED; if(restarter.waitConnected()) return NDBT_FAILED; } NdbSleep_SecSleep(5); // TODO, handle arbitration // Restart one ndbd in each node group SqlResultSet ndbds; if (!atrt.getNdbds(clusterId, ndbds)) return NDBT_FAILED; Vector<NodeInfo> nodes; while (ndbds.next()) { struct NodeInfo n; n.nodeId = ndbds.columnAsInt("node_id"); n.processId = ndbds.columnAsInt("id"); n.nodeGroup = restarter.getNodeGroup(n.nodeId); nodes.push_back(n); } uint ndbdCount = ndbds.numRows(); restartCount = getNodeCount(ndbdNodeSet, ndbdCount); ndbout << "Restarting " << restartCount << " of " << ndbdCount << " ndbds" << endl; int nodesarray[256]; int cnt= 0; Bitmask<4> seen_groups; Bitmask<4> restarted_nodes; for (Uint32 i = 0; (i<nodes.size() && restartCount); i++) { int nodeId = nodes[i].nodeId; int processId = nodes[i].processId; int nodeGroup= nodes[i].nodeGroup; if (seen_groups.get(nodeGroup)) { // One node in this node group already down continue; } seen_groups.set(nodeGroup); restarted_nodes.set(nodeId); ndbout << "Restart node " << nodeId << endl; if (!atrt.changeVersion(processId, args)) return NDBT_FAILED; if (waitNode) { restarter.waitNodesNoStart(&nodeId, 1); } nodesarray[cnt++]= nodeId; restartCount--; } if (!waitNode) { if (restarter.waitNodesNoStart(nodesarray, cnt)) return NDBT_FAILED; } ndbout << "Starting and wait for started..." << endl; if (restarter.startAll()) return NDBT_FAILED; if (restarter.waitClusterStarted()) return NDBT_FAILED; if (event && createDropEvent(ctx, step)) { return NDBT_FAILED; } ndbout << "Half started" << endl; if (ctx->getProperty("HalfStartedHold", (Uint32)0) != 0) { while (ctx->getProperty("HalfStartedHold", (Uint32)0) != 0) { ndbout << "Half started holding..." << endl; ctx->setProperty("HalfStartedDone", (Uint32)1); NdbSleep_SecSleep(30); } ndbout << "Got half started continue..." << endl; } // Restart the remaining nodes cnt= 0; for (Uint32 i = 0; (i<nodes.size() && restartCount); i++) { int nodeId = nodes[i].nodeId; int processId = nodes[i].processId; if (restarted_nodes.get(nodeId)) continue; ndbout << "Restart node " << nodeId << endl; if (!atrt.changeVersion(processId, args)) return NDBT_FAILED; if (waitNode) { restarter.waitNodesNoStart(&nodeId, 1); } nodesarray[cnt++]= nodeId; restartCount --; } if (!waitNode) { if (restarter.waitNodesNoStart(nodesarray, cnt)) return NDBT_FAILED; } ndbout << "Starting and wait for started..." << endl; if (restarter.startAll()) return NDBT_FAILED; if (restarter.waitClusterStarted()) return NDBT_FAILED; if (event && createDropEvent(ctx, step)) { return NDBT_FAILED; } } return NDBT_OK; }
void SimplePathGraph::read ( Iff & iff ) { clear(); // ---------- iff.enterForm(TAG_PGRF); switch (iff.getCurrentName()) { case TAG_0000: m_version = 0; read_0000(iff); break; case TAG_0001: m_version = 1; read_0001(iff); break; default: FATAL(true,("SimplePathGraph::read - Invalid version")); break; } iff.exitForm(TAG_PGRF); // ---------- // Looks like the graph type isn't getting saved out. Patch it up at runtime if(getNodeCount() > 0) { PathNode const * node = getNode(0); PathNodeType type = node->getType(); if(type == PNT_CellPortal || type == PNT_CellWaypoint || type == PNT_CellPOI) { setType(PGT_Cell); } else if(type == PNT_BuildingEntrance || type == PNT_BuildingCell || type == PNT_BuildingPortal || type == PNT_BuildingCellPart) { setType(PGT_Building); } else if(type == PNT_CityBuildingEntrance || type == PNT_CityWaypoint || type == PNT_CityPOI || type == PNT_CityBuilding || type == PNT_CityEntrance) { setType(PGT_City); } else { setType(PGT_None); } } // ---------- int nodeCount = m_nodes->size(); for(int i = 0; i < nodeCount; i++) { m_nodes->at(i).setGraph(this); } // ---------- #ifdef _DEBUG if(ConfigSharedCollision::getBuildDebugData()) { buildDebugData(); } #endif }
CC3Vector CC3NodePuncturingVisitor::getClosestGlobalPunctureLocation() { return getNodeCount() > 0 ? getGlobalPunctureLocationAt( 0 ) : CC3Vector::kCC3VectorNull; }
void PathGraph::setPartTags ( void ) { static PathNodeStack unprocessed; int nodeCount = getNodeCount(); for(int i = 0; i < nodeCount; i++) { PathNode * node = getNode(i); node->setPartId(-1); // ignore nodes without edges unless they're the only node in the cell int edgeCount = getEdgeCount(node->getIndex()); if(edgeCount > 0) { unprocessed.push(node); } else { PathNodeType type = node->getType(); if((nodeCount == 1) && (type == PNT_CellPortal)) { unprocessed.push(node); } } } static PathNodeStack processing; int currentTag = 0; while(!unprocessed.empty()) { PathNode * currentNode = unprocessed.top(); unprocessed.pop(); if(currentNode->getPartId() != -1) continue; processing.push(currentNode); while(!processing.empty()) { PathNode * node = processing.top(); processing.pop(); if(node->getPartId() != -1) continue; node->setPartId(currentTag); int edgeCount = getEdgeCount(node->getIndex()); for(int i = 0; i < edgeCount; i++) { int neighborIndex = getEdge(node->getIndex(),i)->getIndexB(); PathNode * neighborNode = getNode(neighborIndex); processing.push(neighborNode); } } currentTag++; } m_partCount = currentTag; }