CommentNode* BaseCompiler::addComment(const char* str) { CommentNode* node = newComment(str); if (node == NULL) return NULL; return static_cast<CommentNode*>(addNode(node)); }
SpaceBin* SpacePartition::addNode( SearchTree::Node* node, double x, double z ) { int i, j; calcGridCoords( x, z, &i, &j ); return addNode( node, i, j ); }
void KisNodeDummiesGraph::moveNode(KisNodeDummy *node, KisNodeDummy *parent, KisNodeDummy *aboveThis) { removeNode(node); addNode(node, parent, aboveThis); }
void World::build() { int tryCount = 0; bool success = false; while (!success && (tryCount < 50)) { std::cout << "essaie " << tryCount + 1 << std::endl; try { mGrid = Grid(); mNodeArea.clear(); mGateArea.clear(); mAreaPos.clear(); mAreas.clear(); mPaths.clear(); mMapDoorTrigger.clear(); mTmpMap.clear(); long x = 0; long y = 0; long z = 0; Rand_Int<> rand(-10, 10); Rand_Int<> randZ(-1, 1); for (unsigned int i = 1; i <= mGraph->getNodeCount(); ++i) { auto now = std::chrono::high_resolution_clock::now(); bool added = false; int tryCount = 0; INode* node = mGraph->getNode(i); while ((!added) && (tryCount < 1000)) { added = addNode(node, x, y, z); x += rand(); y += rand(); if (!added) { z += randZ(); } tryCount++; } if (!added) { throw std::runtime_error("World::build -> Impossible d'ajouter un noeud au monde"); } std::chrono::duration<double> dt = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - now); std::cout << "Noeud " << i << " ajoute en " << dt.count() << "s" << std::endl; } for (unsigned int i = 1; i <= mGraph->getGateCount(); ++i) { auto now = std::chrono::high_resolution_clock::now(); bool added = false; int tryCount = 0; IGate* gate = mGraph->getGate(i); Id nid1 = gate->getFirstNode(); Id aid1 = mNodeArea[nid1]; std::tuple<long, long, long>& pos1 = mAreaPos[aid1]; Id nid2 = gate->getSecondNode(); Id aid2 = mNodeArea[nid2]; std::tuple<long, long, long>& pos2 = mAreaPos[aid2]; x = (std::get<0>(pos1) + std::get<0>(pos2)) / 2; y = (std::get<1>(pos1) + std::get<1>(pos2)) / 2; z = (std::get<2>(pos1) + std::get<2>(pos2)) / 2; while ((!added) && (tryCount < 1000)) { added = addGate(gate, x, y, z); x += rand(); y += rand(); z += rand(); tryCount++; } if (!added) { throw std::runtime_error("World::build -> Impossible d'ajouter un obstacle au monde"); } std::chrono::duration<double> dt = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - now); std::cout << "Gate " << i << " ajoute en " << dt.count() << "s" << std::endl; } std::cout << "Debut du pathfinding" << std::endl; Pathfinding pf(&mGrid); for (unsigned int gid = 1; gid <= mGraph->getGateCount(); ++gid) { std::cout << "Chemin " << gid << "/" << mGraph->getGateCount() << std::endl; IGate* gate = mGraph->getGate(gid); Id agid = mGateArea.at(gid); Id nid1 = gate->getFirstNode(); Id anid1 = mNodeArea.at(nid1); Id nid2 = gate->getSecondNode(); Id anid2 = mNodeArea.at(nid2); std::tuple<long, long, long> pos1 = mAreaPos.at(anid1) + mAreas.at(anid1).getNextOutCell(); std::tuple<long, long, long> pos2 = mAreaPos.at(agid) + mAreas.at(agid).getNextInCell(); std::tuple<long, long, long> pos3 = mAreaPos.at(agid) + mAreas.at(agid).getNextOutCell(); std::tuple<long, long, long> pos4 = mAreaPos.at(anid2) + mAreas.at(anid2).getNextInCell(); try { std::vector<std::tuple<long, long, long>> p = pf.getPath(pos1, pos2); for (auto& c : p) { mGrid.set(Grid::BLOCK_CELL, c); } mPaths.push_back(p); p = pf.getPath(pos3, pos4); for (auto& c : p) { mGrid.set(Grid::BLOCK_CELL, c); } mPaths.push_back(p); } catch (const std::exception& e) { std::cout << e.what() << std::endl; throw std::runtime_error("Erreur lors de la création d'un chemin"); } } std::cout << "Fin du pathfinding" << std::endl; success = true; } catch (const std::exception& e) { std::cout << e.what() << std::endl; if (tryCount >= 50) { throw std::runtime_error("Impossible de générer un niveau à partir du graphe."); // 1] on ne lance une exception ici que si le nombre d'essais est atteind } } tryCount++; } if (!success) { throw std::runtime_error("Impossible de générer un niveau à partir du graphe: nombre de tentatives atteind"); //Redondant avec 1] ? } else { std::fstream file("temp.g3d", std::fstream::out | std::fstream::trunc); file << mGrid; std::cout << "temp.g3d exported" << std::endl; } std::cout << "map size = " << mMapDoorTrigger.size() << std::endl; mTmpMap.clear(); }
void AntGraph::setFoundTarget( const AntPosition& position ) { addNode( position ); reverseShortestPath(); }
bool wyBox2DCollisionDetector::isCollided(wyNode* node, wyRect& r, wyBox2DCDResult* result) { // init transform 2 sRectTrans2.SetIdentity(); b2Vec2 v; v.x = pixel2Meter(r.x + r.width / 2); v.y = pixel2Meter(r.y + r.height / 2); sRectTrans2.Set(v, 0); // init shape 2 sRectPoly2.SetAsBox(pixel2Meter(r.width) / 2, pixel2Meter(r.height) / 2); // get node hash, if not, add it wyNodeHash* hash = (wyNodeHash*)wyHashSetFind(m_nodeShapes, (size_t)node, node); if(hash == NULL) hash = addNode(node); // update node1 transform wyPoint pos = node->nodeToWorldSpace(wyp(node->getWidth() / 2, node->getHeight() / 2)); v.x = pixel2Meter(pos.x); v.y = pixel2Meter(pos.y); float angle = -wyMath::d2r(node->getRotation()); hash->transform.Set(v, angle); // collision detection bool reverseNormal = false; b2Manifold manifold; switch(hash->type) { case b2Shape::e_polygon: b2CollidePolygons(&manifold, &hash->poly, hash->transform, &sRectPoly2, sRectTrans2); break; case b2Shape::e_circle: b2CollidePolygonAndCircle(&manifold, &sRectPoly2, sRectTrans2, &hash->circle, hash->transform); reverseNormal = true; break; } // to world coordinates if(manifold.pointCount > 0) { // write data back if(result) { // convert to world coordinate b2WorldManifold worldManifold; if(reverseNormal) { worldManifold.Initialize(&manifold, sRectTrans2, sRectPoly2.m_radius, hash->transform, hash->type == b2Shape::e_polygon ? hash->poly.m_radius : hash->circle.m_radius); } else { worldManifold.Initialize(&manifold, hash->transform, hash->type == b2Shape::e_polygon ? hash->poly.m_radius : hash->circle.m_radius, sRectTrans2, sRectPoly2.m_radius); } // save contact points result->pointCount = manifold.pointCount; for(int i = 0; i < manifold.pointCount; i++) { result->points[i] = wyp(meter2Pixel(worldManifold.points[i].x), meter2Pixel(worldManifold.points[i].y)); } // save normal if(reverseNormal) result->normal = wyp(-worldManifold.normal.x, -worldManifold.normal.y); else result->normal = wyp(worldManifold.normal.x, worldManifold.normal.y); } } return manifold.pointCount > 0; }
/* PRE: */ void chQueue::Push(char n) { cqNode^ node = gcnew cqNode(); node->cValue = n; addNode(node); }
void addNewNode(struct node *ptr,int val){ addNode(ptr,initNode(val)); }
void creat_list(int year,int day,int hour,int minute,DownInfo *DI) { if(DI == NULL) return; //download include(daily,hourly,highrate) if( (minute == 0) && (hour == 24) ) { minute = ( minute + 60 - 15 ) % 60; hour = ( hour + 24 - 1 ) % 24; DownInfo *p = DI -> next; while( p != NULL ) { //creat node if( ( strcmp( p->timeType, HOURLY ) == 0 ) || ( strcmp( p->timeType, HIGHRATE ) == 0 ) || ( strcmp( p->timeType, DAILY ) ==0 ) ) { //insert the node at the head DownloadNode *s; s=( DownloadNode* )malloc( sizeof( DownloadNode ) ); memset(s, 0, sizeof( DownloadNode )); add_Info( s, p, year, day, hour, minute ); addNode(s); } p = p->next; } } //download include(hourly,highrate) else if( minute == 0 ) { minute = ( minute + 60 - 15 ) % 60; hour = ( hour + 24 - 1 ) % 24; DownInfo *p = DI->next ; while( p != NULL ) { if( ( strcmp( p->timeType, HOURLY ) == 0 ) || ( strcmp( p-> timeType, HIGHRATE ) == 0 ) ) { //creat node DownloadNode *s; s = ( DownloadNode* )malloc( sizeof( DownloadNode ) ); memset( s, 0, sizeof(DownloadNode) ); add_Info( s, p, year, day, hour, minute ); addNode(s); } //insert the node at the head p = p -> next; } } else {//download include(highrate) minute = ( minute + 60 - 15 ) % 60; DownInfo *p = DI -> next; while( p != NULL ) { if( strcmp( p->timeType, HIGHRATE ) == 0 ) {//creat node DownloadNode *s; s = ( DownloadNode* )malloc( sizeof( DownloadNode ) ); memset(s, 0, sizeof(DownloadNode)); add_Info( s, p, year, day, hour, minute ); addNode(s); } //insert the node at the head p = p->next; } } }
bool SCENEGRAPH::AddChildNode( SGNODE* aNode ) { return addNode( aNode, true ); }
void* handleThem(void* arg) { int sock = *((int*) arg); int i, len; struct recvmsg_t recvmsg; struct sockaddr_in address; // node or client, whatever len = sizeof(address); getpeername(sock, (struct sockaddr*)&address, &len); // new socket structure i = recv(sock, &recvmsg, sizeof(struct recvmsg_t), 0); if (i < 0) { perror("[DRONE] recv error:"); return NULL; } if (recvmsg.mtype == 1) { /* Node requested registration */ pthread_mutex_lock(&mtxMaxBees); while(nodes >= n) { printf("[EAGER BEE] Too many bees (nodes); Waiting...\n"); pthread_cond_wait(&condMaxBees, &mtxMaxBees); } // Add node (Register) addNode(address, recvmsg.port); printf("[DRONE] ++ %d nodes.\n",nodes); printf("[DRONE] Added bee %s : %ld\n",inet_ntoa((*(struct in_addr *)&nodeList[nodes-1].address.sin_addr.s_addr)), nodeList[nodes-1].port); i = 0; printf("[DRONE] Currently available:\n"); while (nodeList[i].address.sin_port != 0) { printf("\t[%d] %s : %ld\n", i+1, inet_ntoa(nodeList[i].address.sin_addr),nodeList[i].port); i = i + 1; } pthread_cond_broadcast(&condMaxBees); pthread_mutex_unlock(&mtxMaxBees); } else if (recvmsg.mtype == 2) { /* Client requested list of nodes */ int ok; listmsg.mtype = 3; //listmsg.nodeList = nodeList; ok = send(sock, &listmsg, sizeof(struct listmsg_t ), 0); if (ok<0) { perror("[DRONE] Send error:"); } printf("[DRONE] Sent polen to the client.\n"); i = 0; printf("[DRONE] Currently available:\n"); while (nodeList[i].address.sin_port != 0) { printf("\t[%d] %s : %ld\n", i+1, inet_ntoa(listmsg.nodeList[i].address.sin_addr),listmsg.nodeList[i].port); i = i + 1; } } else { /* Unrecognized message */ printf("[DRONE] This is some kind of weird bee...\n"); } /* TODO: Node may also disconnect from the hub pthread_mutex_lock(&mtxMaxBees); clients--; printf("-- %d clients.\n",clients); pthread_cond_broadcast(&condMaxBees); pthread_mutex_unlock(&mtxMaxBees); */ sleep(1); close(sock); return NULL; }
bool SCENEGRAPH::AddRefNode( SGNODE* aNode ) { return addNode( aNode, false ); }
void GVSubGraph::addNodes(const QStringList& names) { for(int i=0; i<names.size(); ++i) addNode(names.at(i)); }
Tree addNums(Tree a, Tree b) { Tree r = tree(addNode(a->node(),b->node())); //cerr.flags(ios::showpoint); cerr << "addNums " << *a << "+" << *b << " -> " << *r << endl; return r; }
bool RDirNode::addFile(RFile* f) { //doesnt match this path at all if(f->path.find(abspath) != 0) { if(parent!=0) return false; RDirNode* newparent; std::string common = commonPathPrefix(f->path); if(common.size()==0) common = "/"; newparent = new RDirNode(0, common); newparent->addNode(this); return newparent->addFile(f); } //simply change path of node and add this to it if( parent==0 && abspath == "/" && f->path.compare(abspath) != 0 && fileCount()==0 && dirCount()==0) { debugLog("modifying root path to %s\n", f->path.c_str()); changePath(f->path); } //is this dir - add to this node if(f->path.compare(abspath) == 0) { //debugLog("addFile %s to %s\n", f->fullpath.c_str(), abspath.c_str()); files.push_back(f); if(!f->isHidden()) visible_count++; f->setDir(this); fileUpdated(false); return true; } //does this belong to one of the children ? for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); bool added = child->addFile(f); if(added) return true; } //add new child, add it to that //if commonpath is longer than abspath, add intermediate node, else just add at the files path RDirNode* node = new RDirNode(this, f->path); node->addFile(f); addNode(node); // do we have dir nodes, with a common path element greater than abspath, // if so create another node, and move those nodes there std::string commonpath; vec2f commonPos; for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) { RDirNode* child = (*it); std::string common = child->commonPathPrefix(f->path); if(common.size() > abspath.size() && common != f->path) { commonpath = common; commonPos = child->getPos(); break; } } // redistribute to new common node if(commonpath.size() > abspath.size()) { //debugLog("common path %s\n", commonpath.c_str()); RDirNode* cnode = new RDirNode(this, commonpath); cnode->setPos(commonPos); for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end();) { RDirNode* child = (*it); if(child->prefixedBy(commonpath)) { //debugLog("this path = %s, commonpath = %s, path = %s\n", abspath.c_str(), commonpath.c_str(), child->getPath().c_str()); it = children.erase(it); cnode->addNode(child); continue; } it++; } addNode(cnode); } return true; }
MoulKI::MoulKI(QWidget *parent) : QMainWindow(parent), ui(new Ui::MoulKIClass), gameClient(NULL), authClient(NULL) { resmgr = new plResManager(PlasmaVer::pvMoul); sdlmgr = new plSDLMgr(); ui->setupUi(this); qRegisterMetaType<plUuid>("plUuid"); qRegisterMetaType<plString>("plString"); qRegisterMetaType<uint32_t>("uint32_t"); connect(ui->actionLogin, SIGNAL(triggered()), this, SLOT(showLoginDialog())); connect(ui->actionSet_Active, SIGNAL(triggered()), this, SLOT(showPlayers())); connect(ui->actionFind_Node, SIGNAL(triggered()), this, SLOT(showFindDialog())); connect(ui->actionSubscribe, SIGNAL(triggered()), this, SLOT(showFetchDialog())); connect(ui->actionGet_Public_Ages, SIGNAL(triggered()), this, SLOT(getPublicAgeList())); connect(ui->actionSave_Vault, SIGNAL(triggered()), this, SLOT(writeVault())); connect(ui->actionLoad_Vault, SIGNAL(triggered()), this, SLOT(readVault())); connect(ui->actionJoin_Age, SIGNAL(triggered()), this, SLOT(showJoinAgeDialog())); connect(ui->vaultTree, SIGNAL(itemSelectionChanged()), this, SLOT(setShownNode())); connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveNodeData())); connect(ui->revertButton, SIGNAL(clicked()), this, SLOT(revertNode())); connect(ui->nodeEditor, SIGNAL(isDirty(bool)), this, SLOT(nodeDirty(bool))); connect(ui->vaultTree, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showItemContextMenu(QPoint))); connect(ui->chatEntry, SIGNAL(returnPressed()), this, SLOT(sendGameChat())); connect(&vault, SIGNAL(addedNode(uint32_t, uint32_t)), this, SLOT(addNode(uint32_t,uint32_t))); connect(&vault, SIGNAL(removedNode(uint32_t, uint32_t)), this, SLOT(removeNode(uint32_t,uint32_t))); connect(&vault, SIGNAL(gotRootNode(uint32_t)), this, SLOT(addRoot(uint32_t))); connect(&vault, SIGNAL(updatedNode(uint32_t)), this, SLOT(updateNode(uint32_t))); connect(&vault, SIGNAL(fetchComplete()), this, SLOT(checkCurrentAge())); ui->vaultTree->setContextMenuPolicy(Qt::CustomContextMenu); // set up the player list agePlayersItem = new QTreeWidgetItem(ui->playersTree); agePlayersItem->setText(0, "AGE PLAYERS"); ui->playersTree->insertTopLevelItem(0, agePlayersItem); agePlayersItem->setExpanded(true); buddiesItem = new QTreeWidgetItem(ui->playersTree); buddiesItem->setText(0, "BUDDIES"); buddiesItem->setExpanded(true); ui->playersTree->insertTopLevelItem(0, buddiesItem); neighborsItem = new QTreeWidgetItem(ui->playersTree); neighborsItem->setText(0, "NEIGHBORS"); ui->playersTree->insertTopLevelItem(0, neighborsItem); neighborsItem->setExpanded(true); QList<int> chatSizes; chatSizes.append(350); chatSizes.append(100); ui->chatSplitter->setSizes(chatSizes); ui->nodeEditor->setMgrs(getSDLMgr(), getResManager()); }
bool DynamicGeometryBatch::addNode(MeshRenderableNode* node){ SMesh* m= node->getMesh(); return addNode(m,node->getOwner()); }
void MaterialWindow::OnMenuEvent( wxCommandEvent& evt ) { switch( evt.GetId() ) { // Add Nodes case 0: addNode(mMaterialAsset->getTemplate(), "Opaque"); break; case 1: addNode(mMaterialAsset->getTemplate(), "Float"); break; case 2: addNode(mMaterialAsset->getTemplate(), "Vec2"); break; case 3: addNode(mMaterialAsset->getTemplate(), "Vec3"); break; case 4: addNode(mMaterialAsset->getTemplate(), "Vec4"); break; case 5: addNode(mMaterialAsset->getTemplate(), "Texture"); break; case 6: addNode(mMaterialAsset->getTemplate(), "Time"); break; case 7: addNode(mMaterialAsset->getTemplate(), "Cos"); break; case 8: addNode(mMaterialAsset->getTemplate(), "Sin"); break; case 9: addNode(mMaterialAsset->getTemplate(), "Multiply"); break; case 10: addNode(mMaterialAsset->getTemplate(), "Lerp"); break; // Delete Node case 100: deleteNode(mMaterialAsset->getTemplate(), mHoverNode); break; } }
/* Main Routine */ void main() { struct dubLinkList *head= NULL,*temp=NULL; int more=1,d=0,data=0, a = 0; position pos = LIST_START; printf("Do you want to create a Linked List: Enter 1 for YES 2 for NO:\n"); scanf("%d", &d); if(1==d) { while(more) { printf("\nEnter a number:"); scanf("%d", &data); if(NULL == head) { head=(dubLinkList *)calloc(1, sizeof(struct dubLinkList)); head->next=NULL; head->data=data; head->prev = NULL; temp=head; printf("Head of the Linked List created\n"); } else { temp->next=(dubLinkList *)calloc(1, sizeof(struct dubLinkList)); temp->next->data=data; temp->next->next=NULL; temp->next->prev = temp; temp=temp->next; } printf("\nDo you want to enter one more number: Enter 1 for YES 2 for NO:"); scanf("%d", &a); if(1 == a) more=1; else more=0; } printf("\nPrinting the contents of List\n"); printList(head); more=1; while(more) { printf("\n Enter one of the following choices \n 1. For Adding a number at the Head \ \n 2. For adding a number after another Number \ \n 3. For Adding a number at the Last \ \n 4. Deleting the head of list \ \n 5. Deleting a number from the List \ \n 6. Deleting the last number from the List \ \n 7. Print the contents of the list \ \n 8. For REVERSING the Linked List \n:"); scanf("%d", &d); switch(d) { case 1: pos=LIST_START; addNode(&head, pos); printList(head); break; case 2: pos=LIST_AFTER_A_NUM; addNode(&head, pos); printList(head); break; case 3: pos=LIST_END; addNode(&head, pos); printList(head); break; case 4: pos=LIST_START; delNode(&head, pos); if(NULL != head) { printf("\nThe resulting linked list is "); printList(head); } else printf("\nThe resulting linked list is EMPTY"); break; case 5: pos=LIST_AFTER_A_NUM; delNode(&head, pos); if(NULL != head) { printf("\nThe resulting linked list is "); printList(head); } else printf("\nThe resulting linked list is EMPTY"); break; case 6: pos=LIST_END; delNode(&head, pos); if(NULL != head) { printf("\nThe resulting linked list is "); printList(head); } else printf("\nThe resulting linked list is EMPTY"); break; case 7: printList(head); break; case 8: //reverseList(&head); printf("\nThe resulting linked list is "); printList(head); break; default: printf("\n You have not entered a valid choice \n"); break; } printf("\nDo you want to do one more operation: Enter 1 for YES 2 for NO:"); scanf("%d", &a); if(2 == a) more=0; else more=1; } /* Free the linked list before exiting from the program */ if(head) freeList(&head); } getche(); }
unsigned int receiveSymbFLY(LTdecoderFLY *decoder, BucketFLY *bucket, char *encodedInfo, // encodedInfo is the vector of encoded bits unsigned int encodedInfoLength, // length of the encodedInfo vector (thus number of encoded bits) unsigned int IDfirstSymb, // ID of the first encoded symbol unsigned long offset) { // ID of the first source symbol considered in the encoding window unsigned int i; unsigned int count = 0; Node *ptr= NULL; unsigned int packetSymbols = (unsigned int)(encodedInfoLength/(bucket->symbLen)); if (IDfirstSymb+packetSymbols > bucket->genSymbs) { createHeadersFly(bucket, (IDfirstSymb+packetSymbols)-(bucket->genSymbs), offset); } for (i=0; i<packetSymbols; i++) { // Create Node if (decoder->RXsymbList == NULL) { ptr = addNode(NULL); decoder->RXsymbList = ptr; } else { ptr = addNode(decoder->lastRXsymbol); decoder->lastRXsymbol->next = ptr; } decoder->lastRXsymbol = ptr; count++; // Alloc a new symbol in the decoder ptr->data = (Symbol *) chk_calloc(1, sizeof(Symbol)); Symbol *newSymbol = (Symbol *)ptr->data; // Create pointer to the current symbol in the bucket Symbol* currSymbol = &(bucket->symbols[IDfirstSymb+i]); // Deg newSymbol->deg = currSymbol->deg; // Symb Len newSymbol->symbLen = currSymbol->symbLen; // Header newSymbol->header = (unsigned int *)chk_malloc(newSymbol->deg, sizeof(unsigned int)); memcpy(newSymbol->header, currSymbol->header, newSymbol->deg*sizeof(unsigned int)); // Info newSymbol->info = (char *)chk_malloc(bucket->symbLen, sizeof(char)); memcpy(newSymbol->info, &encodedInfo[i*bucket->symbLen], bucket->symbLen*sizeof(char)); #ifdef DEBUGdecoderPrintHeaders int deb_index; printf("DECODER[%d] - symb[%d]\t: deg=%3d\t -> ", bucket->nameBucket, IDfirstSymb+i, newSymbol->deg); for (deb_index=0; deb_index<newSymbol->deg; deb_index++) printf("%3d ", currSymbol->header[deb_index]); printf("\n"); #endif } // Update the number of received symbols decoder->NumRecSymbols += count; return count; }
for each(char n in range) { cqNode^ node = gcnew cqNode(); node->cValue = n; addNode(node); }
int qini_ParseFile ( FILE *f, tree_sTable *ntp, int *warnings, int *errors, int *fatals ) { pwr_tStatus sts = 1; int n; char *s; char buffer[256]; int error = 0; char name[80]; char s_nid[80]; char s_naddr[80]; char s_port[80]; char s_connection[80]; char s_min_resend_time[80]; char s_max_resend_time[80]; pwr_tNodeId nid; struct in_addr naddr; qini_sNode *nep; struct arpreq arpreq; while ((s = fgets(buffer, sizeof(buffer) - 1, f)) != NULL) { if (*s == '#' || *s == '!') { s++; continue; } n = sscanf(s, "%s %s %s %s %s %s %s", name, s_nid, s_naddr, s_port, s_connection, s_min_resend_time, s_max_resend_time); if (n < 3) { errh_Error("error in line, <wrong number of arguments>, skip to next line.\n>> %s", s); (*errors)++; continue; } sts = cdh_StringToVolumeId(s_nid, (pwr_tVolumeId *)&nid); if (EVEN(sts)) { errh_Error("error in line, <node identity>, skip to next line.\n>> %s", s); (*errors)++; continue; } sts = net_StringToAddr( s_naddr, &naddr); if ( EVEN(sts)) { errh_Error("error in line, <network address>, skip to next line.\n>> %s", s); (*errors)++; continue; } #if 0 naddr.s_addr = inet_network(s_naddr); #if defined(OS_VMS) if (naddr.s_addr == (in_addr_t)-1) { #else if (naddr.s_addr == (unsigned int)-1) { #endif /* Try name instead */ struct addrinfo hints; struct addrinfo *res; int err; memset((void*)&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; err = getaddrinfo(s_naddr, 0, &hints, &res); if ( err < 0) { errh_Error("error in line, <network address>, skip to next line.\n>> %s", s); (*errors)++; continue; } switch ( res->ai_family) { case AF_INET: // memcpy( &naddr.s_addr, (char *)&res->ai_addr->sa_data + 2, 4); memcpy( &naddr.s_addr, &((struct sock_addr_in *)res->ai_addr)->sin_addr, 4); naddr.s_addr = ntohl( naddr.s_addr); break; case AF_INET6: break; } freeaddrinfo( res); } #endif nep = tree_Find(&sts, ntp, &nid); if (nep != NULL) { errh_Warning("node is allready defined: %s, skip to next line", s); (*warnings)++; continue; } else { nep = tree_Insert(&sts, ntp, &nid); } strcpy(nep->name, name); nep->naddr.s_addr = htonl(naddr.s_addr); if (n > 3) nep->port = htons(atoi(s_port)); if (n > 4) nep->connection = atoi(s_connection); if (n > 5) nep->min_resend_time = atoi(s_min_resend_time); if (n > 6) nep->max_resend_time = atoi(s_max_resend_time); memset(&arpreq, 0, sizeof(arpreq)); memcpy(&arpreq.arp_pa.sa_data, &naddr, sizeof(naddr)); inet_GetArpEntry(&sts, 0, &arpreq); } return error; } pwr_tBoolean qini_BuildDb ( pwr_tStatus *sts, tree_sTable *nodes, qini_sNode *me, #if 0 /* change when new class NetConfig is deined */ pwr_sNetConfig *cp, #else void *cp, #endif qcom_tBus bus ) { qdb_sInit init; qdb_sNode *np; qini_sNode *nep; void *p; qdb_sAppl *ap; memset(&init, 0, sizeof(init)); init.nid = me->nid; init.bus = bus; init.nodes = nodes->nNode; #if 0 /* change when new class NetConfig is deined */ init.queues = cp->Queues; init.applications = cp->Applications; init.sbufs = cp->SmallCount; init.mbufs = cp->MediumCount; init.lbufs = cp->LargeCount; init.size_sbuf = cp->SmallSize; init.size_mbuf = cp->MediumSize; init.size_lbuf = cp->LargeSize; #endif p = qdb_CreateDb(sts, &init); if (p == NULL) return NO; qdb_ScopeLock { for (nep = tree_Minimum(sts, nodes); nep != NULL; nep = tree_Successor(sts, nodes, nep)) { np = addNode(nep); } ap = qdb_AddAppl(NULL, YES); qdb->exportque = addQueue(NULL, qdb_cIexport, "export", qdb_eQue_private, qdb_mQue_system); addQueue(ap, qcom_cInetEvent, "netEvent", qdb_eQue_forward, qdb_mQue_system); addQueue(ap, qcom_cIapplEvent, "applEvent", qdb_eQue_forward, qdb_mQue_system); addQueue(ap, qcom_cImhAllHandlers, "allHandlers", qdb_eQue_forward, qdb_mQue_broadcast); addQueue(ap, qcom_cImhAllOutunits, "allOutunits", qdb_eQue_forward, qdb_mQue_broadcast); addQueue(ap, qcom_cIhdServer, "hdServer", qdb_eQue_forward, qdb_mQue_broadcast); addQueue(ap, qcom_cIhdClient, "hdClient", qdb_eQue_forward, qdb_mQue_broadcast); #if !defined OS_CYGWIN addQueue(NULL, qcom_cInacp, "nacp", qdb_eQue_private, qdb_mQue_system); #endif addQueue(ap, qcom_cIini, "ini", qdb_eQue_forward, qdb_mQue_system | qdb_mQue_event); } qdb_ScopeUnlock; return (YES); }
void MeshComplex::addNode(const QPointF &p) { addNode(p.x(), p.y()); }
bool QueapTree<T>::addNode(TreeNode<T>* parent, T ele,int height) { static vector<TreeNode<T>*> split; static vector<TreeNode<T>*> pointerList; if(parent == nullptr) // root { int temp_height = height; TreeNode<T>* temp = new TreeNode<T>(T(numeric_limits<char>::max(),numeric_limits<char>::max())); root_->parent_ = temp; temp->child_[0] = root_; root_->hvcv_ = true; root_->p_ = nullptr; root_ = temp; root_->count_++; height_+=1; // increase height of tree. TreeNode<T>* temp_parent = root_; while(temp_height--) { TreeNode<T>* temp = new TreeNode<T>(T(numeric_limits<char>::max(),numeric_limits<char>::max())); // cout << "bool1: "<< temp->hvcv_ << endl; temp->parent_ = temp_parent; temp_parent->count_++; temp_parent->child_[temp_parent->count_] = temp; if(!split.empty()) { TreeNode<T>* t = split.back(); temp->child_[++temp->count_] = t; t->parent_->child_[t->parent_->count_--] = nullptr; // recompute the pointers for the prev parent of the split node (only if the node pointer is not cv) if(t->parent_->hvcv_ == false) { // cout << "boob\n"; pointerList.resize(0); for(int i = 0; i <= t->parent_->count_; i++) { pointerList.push_back(t->parent_->child_[i]); } t->parent_->p_ = minPointer(pointerList); t->parent_->ele_ = t->parent_->p_->ele_; } t->parent_ = temp; // change parent split.pop_back(); } temp_parent = temp; } TreeNode<T>* temp2 = new TreeNode<T>(ele); temp_parent->count_++; temp_parent->child_[temp_parent->count_] = temp2; temp2->parent_ = temp_parent; pointerList.resize(0); for(int i = 0; i <= temp_parent->count_; i++) { pointerList.push_back(temp_parent->child_[i]); } temp_parent->p_ = minPointer(pointerList); temp_parent->ele_ = temp_parent->p_->ele_; updatePointerPath(temp_parent->parent_); } else if(parent->count_ + 1 > 3) { height++; split.push_back(parent->child_[3]); addNode(parent->parent_,ele,height); } else { int temp_height = height; TreeNode<T>* temp_parent = parent; while(temp_height--) { TreeNode<T>* temp = new TreeNode<T>(T(numeric_limits<char>::max(),numeric_limits<char>::max())); temp->parent_ = temp_parent; temp_parent->count_++; temp_parent->child_[temp_parent->count_] = temp; temp_parent = temp; if(!split.empty()) { TreeNode<T>* t = split.back(); temp->child_[++temp->count_] = t; t->parent_->child_[t->parent_->count_--] = nullptr; if(t->parent_->hvcv_ == false) { pointerList.resize(0); for(int i = 0; i <= t->parent_->count_; i++) { pointerList.push_back(t->parent_->child_[i]); } t->parent_->p_ = minPointer(pointerList); t->parent_->ele_ = t->parent_->p_->ele_; } t->parent_ = temp; // change parent split.pop_back(); } } TreeNode<T>* temp2 = new TreeNode<T>(ele); temp_parent->count_++; temp_parent->child_[temp_parent->count_] = temp2; temp2->parent_ = temp_parent; pointerList.resize(0); for(int i = 0; i <= temp_parent->count_; i++) { pointerList.push_back(temp_parent->child_[i]); } temp_parent->p_ = minPointer(pointerList); temp_parent->ele_ = temp_parent->p_->ele_; updatePointerPath(temp_parent->parent_); } return true; }
void Graph::addNodes(const NodeList& nodes) { mNodes.clear(); for (size_t i = 0; i < nodes.size(); ++i) addNode(nodes[i]); }
void Tetgen::fineTetra() { int i; int n; Tetra* crtet; Node* nd0,* nd1,* nd2,* nd3; Node* new_nd; Point tmp_pt; double vol; double dist; double mindens,minvol; double nx,ny,nz,nden; int flg; vector<int> tet_id_buff; if(!cr_crowd) return; mindens = cr_crowd->getCurrentMinDensity(); minvol = mindens * mindens * mindens * rate_minvolm; flg = 1; while(flg) { flg = 0; n = getSize(); for(i = 0; i < n; i++) { crtet = getTetra(i); vol = crtet->getVolume(); if(vol < minvol) continue; nd0 = crtet->getNode(0); nd1 = crtet->getNode(1); nd2 = crtet->getNode(2); nd3 = crtet->getNode(3); nx = (nd0->getX() + nd1->getX() + nd2->getX() + nd3->getX()) * 0.25; ny = (nd0->getY() + nd1->getY() + nd2->getY() + nd3->getY()) * 0.25; nz = (nd0->getZ() + nd1->getZ() + nd2->getZ() + nd3->getZ()) * 0.25; tmp_pt.setCoordinates(nx,ny,nz); dist = getDistance(&tmp_pt,nd0); if(nd0->getDensity() > dist * rate_density) continue; dist = getDistance(&tmp_pt,nd1); if(nd1->getDensity() > dist * rate_density) continue; dist = getDistance(&tmp_pt,nd2); if(nd2->getDensity() > dist * rate_density) continue; dist = getDistance(&tmp_pt,nd3); if(nd3->getDensity() > dist * rate_density) continue; flg = 1; nden = (nd0->getDensity() + nd1->getDensity() + nd2->getDensity() + nd3->getDensity()) * 0.25; new_nd = cr_crowd->makeNewNode(nx,ny,nz,nden); new_nd->setType(3); //remeshing tet_id_buff.clear(); addNode(tet_id_buff,crtet,new_nd); if(!tet_id_buff.size()) { cr_crowd->erase(new_nd->getId()); continue; } n = getSize(); } //for i } //while flg /* view(); getch(); setTetHanger(); Node *nnd = cr_crowd->getNode(202); nnd->view(); getch(); eraseNode(nnd); nnd = cr_crowd->getNode(203); nnd->view(); getch(); eraseNode(nnd); getch(); view(); getch(); */ }
/** * @brief Returns the (indirect) successor node of the given statement @a stmt. * * This function may add new nodes. */ ShPtr<CFG::Node> RecursiveCFGBuilder::getIndirectSuccessor(ShPtr<Statement> stmt) { if (isa<ContinueStmt>(stmt)) { // A continue statement has to be inside of a loop. ShPtr<Statement> innLoop(getInnermostLoop(stmt)); if (!innLoop) { return cfg->getExitNode(); } return addNode(innLoop); } if (isa<BreakStmt>(stmt)) { // A break statement has to be inside a loop or switch. ShPtr<Statement> innLoopOrSwitch(getInnermostLoopOrSwitch(stmt)); if (!innLoopOrSwitch) { return cfg->getExitNode(); } if (ShPtr<Statement> succ = innLoopOrSwitch->getSuccessor()) { return addNode(succ); } return getIndirectSuccessor(innLoopOrSwitch); } ShPtr<Statement> stmtParent(stmt->getParent()); if (!stmtParent) { // There is an implicit return from the function. return cfg->exitNode; } if (isLoop(stmtParent)) { return addNode(stmtParent); } if (isa<IfStmt>(stmtParent) && stmtParent->getSuccessor()) { return addNode(stmtParent->getSuccessor()); } if (ShPtr<SwitchStmt> stmtParentSwitch = cast<SwitchStmt>(stmtParent)) { // There should be a fall-through to the next switch clause (or to the // switch's successor, if there is no next clause). // Find out in which clause we are. auto i = stmtParentSwitch->clause_begin(); auto e = stmtParentSwitch->clause_end(); while (i != e) { if (isStatementInStatements(stmt, i->second)) { break; } ++i; } // Create an edge to the next clause (if any). ++i; if (i != e) { // There is a next clause. return addNode(i->second); } } // Traverse over parents (of parents) until a parent with a successor is // found. If there is no such parent, then there is an implicit return from // the current function. do { if (ShPtr<Statement> stmtParentSucc = stmtParent->getSuccessor()) { return addNode(stmtParentSucc); } } while ((stmtParent = stmtParent->getParent())); // There is an implicit return from the function. return cfg->exitNode; }
void main() { LLnode *first = NULL; // Pointer to start of list LLnode *temp; char *cmd = NULL; // Input command int inVal; // Input value char sorted; // Test to see if list should be sorted char junk; // Used to hold newline // Ask user to determine if list should be sorted printf("Use sorted linked list? (Y/N) "); scanf("%c%c", &sorted, &junk); do { printf("\nEnter command: "); cmd = readLine(); // Read string from standard input // Add integer to list if (strcmp(cmd, "add") == 0) { printf("Enter number to be added: "); scanf("%d%c", &inVal, &junk); // Choose between sorted/unsorted list functions if (sorted == 'Y') first = addSortedNode(first, inVal); else first = addNode(first, inVal); } // Delete word from list else if (strcmp(cmd, "delete") == 0) { printf("Enter number to be deleted: "); scanf("%d%c", &inVal, &junk); first = delNode(first, inVal); } // Find word in list else if (strcmp(cmd, "find") == 0) { printf("Enter number to be found: "); scanf("%d%c", &inVal, &junk); // Choose between sorted/unsorted list functions if (sorted == 'Y') temp = findSortedNode(first, inVal); else temp = findNode(first, inVal); if (temp == NULL) printf("%d not found in list\n", inVal); else printf("%d found in list\n", inVal); } // Print contents of entire list else if (strcmp(cmd, "print") == 0) printList(first); // Invalid command else if (strcmp(cmd, "exit") != 0) printf("Invalid command %s\n", cmd); } while (strcmp(cmd, "exit") != 0); }
bool AbstractNetworkManager::configAdd(jccl::ConfigElementPtr element) { if (recognizeClusterMachineConfig(element)) { // -If local machine element // -Add machine specific ConfigElements to the pending list. // -Start Listening thread // -Else // -Add Node to AbstractNetworkManager if (isLocalHost( element->getProperty<std::string>( "host_name" ) )) { // XXX: Hack to ensure that we don't start listening for connections until // we have fully configured all other nodes. ElementPred pred(getClusterNodeElementType()); jccl::ConfigManager* cfg_mgr = jccl::ConfigManager::instance(); unsigned int num_pending_nodes = std::count_if(cfg_mgr->getPendingBegin(), cfg_mgr->getPendingEnd(), pred); if (num_pending_nodes > 1) { vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) << clrSetBOLD(clrRED) << clrOutBOLD( clrMAGENTA,"[AbstractNetworkManager]" ) << " Some nodes not configured yet: " << num_pending_nodes << clrRESET << std::endl << vprDEBUG_FLUSH; return false; } // NOTE: Add all machine dependent ConfigElementPtr's here vprASSERT( element->getNum("display_system") == 1 && "A Cluster System element must have exactly 1 display_system element" ); std::vector<jccl::ConfigElementPtr> cluster_node_elements = element->getChildElements(); for (std::vector<jccl::ConfigElementPtr>::iterator i = cluster_node_elements.begin(); i != cluster_node_elements.end(); ++i) { jccl::ConfigManager::instance()->addConfigElement(*i, jccl::ConfigManager::PendingElement::ADD); vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) << clrSetBOLD(clrCYAN) << clrOutBOLD( clrMAGENTA,"[AbstractNetworkManager]" ) << " Adding Machine specific ConfigElement: " << (*i)->getName() << clrRESET << std::endl << vprDEBUG_FLUSH; } const int listen_port = element->getProperty<int>( "listen_port" ); startListening( listen_port, false ); } else { vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL ) << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" ) << " Adding Node: " << element->getName() << " to the Cluster Network\n" << vprDEBUG_FLUSH; std::string name = element->getName(); std::string host_name = element->getProperty<std::string>( "host_name" ); vpr::Uint16 listen_port = element->getProperty<int>( "listen_port" ); addNode(name, host_name, listen_port); } return true; } return false; }
EmbedNode* BaseCompiler::addEmbed(const void* data, uint32_t size) { EmbedNode* node = newEmbed(data, size); if (node == NULL) return node; return static_cast<EmbedNode*>(addNode(node)); }