int main(){ char buf[1000]; FILE *ptr_file; typeCount = 7; ptr_file =fopen("Lexar.c","r"); if (!ptr_file) return 1; while (fgets(buf,1000, ptr_file)!=NULL) { trim(buf); if((*(buf)=='/' && *(buf+1)=='/') || !strcmp(buf,"\n")){ printf("%d[%d]. ---- empty line or comment \n", slNo++, lnNo); }else if ((!strcmp(buf, "}\n")) || (!strcmp(trim(buf), "}"))){ printf("%d[%d]. ____ Closing curly bracket.\n\n", slNo++, lnNo); }else{ if(!incLib(buf)){ // if the statement is not header strcpy(temp, buf); token = strtok(temp, ";"); token = strtok(token, " "); // Methods and var if(!strcmp(token, "struct")){ token = strtok(NULL, "{"); printf("%d[%d]. Declaring Structure \"%s\" \n",slNo++, lnNo, token); bType[typeCount++] = token; }else if(belongsTo(token, bType, typeCount)){ strcpy(temp, buf); if(!decMethod(temp)){ strcpy(temp, buf); if(decVar(temp)) //if assigned with declaration decnAsgn(buf); //printf("%d[%d]. Are Variable \n", slNo++, lnNo); } }else{ while((*token) == '}') token++; if(belongsTo(token = strtok(token, "("), clYpye, 6)){ printf("%d[%d]. Conditional Logic \"%s\"\n", slNo++, lnNo, token); }else if(!strcmp(token, "return")){ printf("%d[%d]. End of function \n", slNo++, lnNo); }else{ printf("%d[%d]. Function call for \"%s\"\n", slNo++, lnNo, token); } } } } lnNo++; } fclose(ptr_file); printf("==============================\n\n\n"); printTable(); return 0; }
short DBManager::getFloorButton() { char query[MAX_STR_LENGTH]; sqlite3_stmt* statement; vector<short>* elems = get_valid_elems("PuzzleElem"); short gfxId = -1; if (elems->size() > 0) { sprintf(query, "select id, type, gfxId from PuzzleElem where type = %d", 0); if (db_status && SQLITE_OK == sqlite3_prepare(db, query, MAX_STR_LENGTH, &statement, NULL)) { puzzle_elem_t p; int id = -1; while (!belongsTo(id, elems) && SQLITE_ROW == sqlite3_step(statement)) id = (short) sqlite3_column_int(statement, 0); p.id = id; p.type = (short) sqlite3_column_int(statement, 1); p.gfxId = (short) sqlite3_column_int(statement, 2); gfxId = p.gfxId; puzzle_elems->insert(p); } else db_status = false; sqlite3_finalize(statement); } delete elems; elems = NULL; return gfxId; }
void ClipmapRing::reposition(const ivec3& _pos, const ivec3& _innerPos){ ivec3 origin = ring[calcRingIndex(start.x,start.y, start.z)].pos; ivec3 diff = _pos - origin; // we expect the values in diff should be either zero, or unitSize ivec3 normalizedDiff = diff / unitSize; start += normalizedDiff; ivec3 start = ivec3_mod(start, RING_DIM); //int z = 0; { for (int z = 0; z < RING_DIM; z++){ for (int y = 0; y < RING_DIM; y++){ for (int x = 0; x < RING_DIM; x++){ ivec3 thisPos = _pos + ivec3(x, y, z) * unitSize; // find the corresponding node. ivec3 nxyz = ivec3_mod(ivec3(x + start.x, y + start.y, z + start.z), RING_DIM); int idx = calcRingIndex(nxyz.x, nxyz.y, nxyz.z); ivec3 posFromNode = ring[idx].pos; bool inRing; if (noInner)inRing = belongsToNoInner(thisPos, _pos); else inRing = belongsTo(thisPos, _pos, _innerPos); if (inRing){ if (ring[idx].activated == 1){ if (posFromNode == thisPos){ // keep printf_s("keep %d, %d, %d\n", thisPos.x, thisPos.y, thisPos.z); } else{ // remove and regenerate printf_s("remove %d, %d, %d === generate %d, %d, %d\n", posFromNode.x, posFromNode.y, posFromNode.z, thisPos.x, thisPos.y, thisPos.z); ring[idx].pos = thisPos; vcManager->relocateChunk(&ring[idx], thisPos); } } else{ // first allocation printf_s("claim %d, %d, %d\n", thisPos.x, thisPos.y, thisPos.z); ring[idx].activated = 1; ring[idx].pos = thisPos; vcManager->createChunk(thisPos, lod, &ring[idx]); } } else{ if (ring[idx].activated == 1){ printf_s("release %d, %d, %d\n", thisPos.x, thisPos.y, thisPos.z); ring[idx].activated = 0; vcManager->removeChunk(&ring[idx]); } } } } } }
void ClipmapRing::createEdgeDescs(ClipmapRing* innerRing, ClipmapRing* outterRing){ const ivec3 adjacencyInfo[6] = { ivec3(-unitSize, 0, 0), ivec3(0, -unitSize, 0), ivec3(0, 0, -unitSize), ivec3(0, -unitSize, -unitSize), ivec3(-unitSize, 0, -unitSize), ivec3(-unitSize, -unitSize, 0) }; for (int z = 0; z < RING_DIM; z++){ for (int y = 0; y < RING_DIM; y++){ for (int x = 0; x < RING_DIM; x++){ bool inRing; ivec3 thisPos = originPos + ivec3(x, y, z) * unitSize; if (noInner)inRing = belongsToNoInner(thisPos, originPos); else inRing = belongsTo(thisPos, originPos, innerCubePos); if (inRing){ ivec3 nxyz = ivec3_mod(ivec3(x + start.x, y + start.y, z + start.z), RING_DIM); int idx = calcRingIndex(nxyz.x, nxyz.y, nxyz.z); VoxelChunk* curChunk = ring[idx].chunk; for (int i = 0; i < 6; i++){ ivec3 adjPos = ring[idx].pos + adjacencyInfo[i]; int adjType = adjacencyTypes(adjPos); if (i < 3){ if (adjType == 0){ // a normal 1 to 1 relationship. const VCNode* adjNode = getNodeByCoord(adjPos); curChunk->createEdgeDesc2D(adjType, 0, 0, adjNode->chunk, i); } else if(adjType == 1){ // now there are 4 chunks that are adjacent to curChunk. // they lie in the ring inside this clipmap ring. VCNode node0, node1, node2, node3; innerRing->getNodesFromInner(adjPos, i, &node0, &node1, &node2, &node3); curChunk->createEdgeDesc2D(adjType, 0, 0, node0.chunk, i); curChunk->createEdgeDesc2D(adjType, 1, 0, node1.chunk, i); curChunk->createEdgeDesc2D(adjType, 0, 1, node2.chunk, i); curChunk->createEdgeDesc2D(adjType, 1, 1, node3.chunk, i); } else if (adjType == -1){ // the adjacent chunk is larger than curChunk. // curChunk only has enough data to describe 1 / 4 of its edge desc. ivec3 local = ivec3_mod(adjPos, unitSize); ivec3 tempAdjPos = adjPos - local; const VCNode* adjNode = outterRing->getNodeByCoord(tempAdjPos); if ( i == 0) curChunk->createEdgeDesc2D(adjType, local.z, local.y, adjNode->chunk, i); } } else{ } } } } } } }
void DBManager::getDoors() { char query[MAX_STR_LENGTH]; sqlite3_stmt* statement; vector<short>* elems = get_valid_elems("Door"); int n_doors = elems->size(); if (n_doors > 0) { sprintf(query, "select id, pathG from Door where type = 0"); if (db_status && SQLITE_OK == sqlite3_prepare(db, query, MAX_STR_LENGTH, &statement, NULL)) { int id = -1; while (!belongsTo(id, elems) && SQLITE_ROW == sqlite3_step(statement)) id = (short) sqlite3_column_int(statement, 0); char aux[MAX_STR_LENGTH]; sprintf(aux, "%s", sqlite3_column_text(statement, 1)); doorPath = aux; } else db_status = false; sprintf(query, "select id, pathG from Door where type = 1"); if (db_status && SQLITE_OK == sqlite3_prepare(db, query, MAX_STR_LENGTH, &statement, NULL)) { int id = -1; while (!belongsTo(id, elems) && SQLITE_ROW == sqlite3_step(statement)) id = (short) sqlite3_column_int(statement, 0); char aux[MAX_STR_LENGTH]; sprintf(aux, "%s", sqlite3_column_text(statement, 1)); bossDoorPath = aux; } else db_status = false; sqlite3_finalize(statement); } delete elems; elems = NULL; }
QList<int> QtGroupingProxy::addSourceRow( const QModelIndex &idx ) { QList<int> updatedGroups; QList<RowData> groupData = belongsTo( idx ); //an empty list here means it's supposed to go in root. if( groupData.isEmpty() ) { updatedGroups << -1; if( !m_groupHash.keys().contains( -1 ) ) m_groupHash.insert( -1, QList<int>() ); //add an empty placeholder } //an item can be in multiple groups foreach( RowData data, groupData ) { int updatedGroup = -1; if( !data.isEmpty() ) { // qDebug() << QString("index %1 belongs to group %2").arg( row ) // .arg( data[0][Qt::DisplayRole].toString() ); foreach( const RowData &cachedData, m_groupMaps ) { //when this matches the index belongs to an existing group if( data[0][Qt::DisplayRole] == cachedData[0][Qt::DisplayRole] ) { data = cachedData; break; } } updatedGroup = m_groupMaps.indexOf( data ); //-1 means not found if( updatedGroup == -1 ) { //new groups are added to the end of the existing list m_groupMaps << data; updatedGroup = m_groupMaps.count() - 1; } if( !m_groupHash.keys().contains( updatedGroup ) ) m_groupHash.insert( updatedGroup, QList<int>() ); //add an empty placeholder }
void ClipmapRing::initPos(ivec3 _pos, ivec3 _innerPos, int _lod){ lod = _lod; unitSize = 1 << lod; noInner = false; for (int z = 0; z < RING_DIM; z++){ for (int y = 0; y < RING_DIM; y++){ for (int x = 0; x < RING_DIM; x++){ int idx = calcRingIndex(x, y, z); ivec3 thisPos = _pos + ivec3(x, y, z) * unitSize; ring[idx].pos = thisPos; if (belongsTo(thisPos, _pos, _innerPos)){ ring[idx].activated = 1; vcManager->createChunk(ring[idx].pos, lod, &ring[idx]); } } } } originPos = _pos; innerCubePos = _innerPos; start = ivec3(0, 0, 0); }
int GreenExplorator::generateMutations(IceQuiver &pe) { //int i; int ret; int vertex; //int create=0; unsigned int size; std::string mutations_str=""; std::string filename = ""; std::vector<int> mutations_v; std::stringstream ss (std::stringstream::in | std::stringstream::out); IceQuiver p = pe; strhash::iterator iit; std::map<uint64_t,mpz_class>::iterator mult_it; std::map<uint64_t,mpz_class> *mult; vecivect::iterator vi; #ifdef DEBUG std::cout << "genMut: Working on "; pe.printMutationsE(0); #endif vertex = pe.getNextFiniteGreenVertex(); if(vertex == -1) { return 1;//No more finite green vertex } if(vertex==p.lastMutation()) { // No need to mutate twice on the same vertex return 1; } if(p.getMutationsSize() >= this->max_depth) { return 4;//Cut the sequence } ret = p.mutate(vertex); if (ret == 0) { // if mutate returned 0, then non-BHIT violating infinity was detected return 0; } if (ret == 1) { //A maximal green sequence/tail was detected or infinity was detected! size = p.getMutationsSize(); mult = p.getMultiplicityMap(); printVectors(p.getAdmittedCVectors()); if (!p.getAdmittedCVectors().empty()) { for (vi = p.admittedCVectors.begin(); vi != p.admittedCVectors.end(); vi++) { if (!belongsTo(*vi, admissibleCVectors)) admissibleCVectors.push_back(*vi); } } printVectors(p.getAdmittedGVectors()); if (!p.getAdmittedGVectors().empty()) { for (vi = p.admittedGVectors.begin(); vi != p.admittedGVectors.end(); vi++) { if (!belongsTo(*vi, admissibleGVectors)) admissibleGVectors.push_back(*vi); } } printVectors(p.getAdmittedPVectors()); if (!p.getAdmittedPVectors().empty()) { for (vi = p.admittedPVectors.begin(); vi != p.admittedPVectors.end(); vi++) { if (!belongsTo(*vi, admissiblePVectors)) admissiblePVectors.push_back(*vi); } } #ifdef DEBUG printVectors(admissibleCVectors); printVectors(admissibleGVectors); printVectors(admissiblePVectors); std::cout << "MGS found!" << std::endl; p.printMutationsE(0); #endif for(mult_it = mult->begin(); mult_it!=mult->end(); mult_it++) { mgsInfo[mult_it->first] += mult_it->second; #ifdef DEBUG std::cout << mult_it->first << "," << mult_it->second << std::endl; #endif } if (isomorphTest) { mutations_v = p.getMutations(); gsh.increment(mutations_v,size); } if(size > maxLength) { maxLength = size; // std::cerr << "M:"; //p.printMutationsE(1); //std::cerr << "Q:"; //p.printMutationsE(0); } if(size < minLength) { minLength = size; //std::cerr << "m:"; //p.printMutationsE(1); //std::cerr << "Q:"; //p.printMutationsE(0); } numGreen+=1; if((numGreen % 100000) == 0) { //#ifdef DEBUG std::cerr << "S (" << numGreen << "):"; p.printMutationsE(0); //#endif } if(isomorphTest) {insertInCemetary(p,cemetary);} return 0; } if (isomorphTest) { return insertInList(p); } else { c.push_back(p); return 2; } /*#ifdef DEBUG std::cout << "Fin du travail avec "; p.printMutations(0); #endif*/ }
int GreenExplorator::insertInList(IceQuiver &pe) { std::list<IceQuiver>::iterator ri; std::list<IceQuiver>::reverse_iterator rxi; std::map<uint64_t,mpz_class>::iterator it_mul; std::map<uint64_t,mpz_class> *mul_map; std::map<uint64_t,mpz_class> tmp; std::map<uint64_t,mpz_class> *green_sizes; std::map<uint64_t,mpz_class>::iterator it; strhash::iterator iit; std::string mutations_str=""; std::vector<int> mutations_v; vecivect::iterator vi; //int i; uint64_t pe_size,n_size; std::stringstream ss (std::stringstream::in | std::stringstream::out); // ri is an iterator, it browses the list from the beginning //1.If pe is in c then add the multiplicity of pe to the already existing copy of it (*ri). for(ri=c.begin();ri!=c.end();ri++) { if(this->myIsomorphismNauty(pe,*ri)) { #ifdef DEBUG pe.printMutations(0); std::cout << "Is isomorphic to "; (*ri).printMutations(0); std::cout << "\n"; #endif // This principal extension is still to be considered // increase its multiplicity (*ri).addMultiplicity(pe); //(!!) break; } } if( ri != c.end()) { return 0;}//No addition in this case. Just change the multiplicity. for(rxi=cemetary.rbegin();rxi!=cemetary.rend();rxi++) { if(this->myIsomorphismNauty(pe,*rxi)) { #ifdef DEBUG pe.printMutations(0); std::cout << "Is isomorphic to (C) "; (*rxi).printMutations(0); std::cout << "\n"; #endif // This quiver is isomorph to a cemetary quiver mutations_str = (*rxi).getMutationsString(); if(gsh.GreenSizesGetSize(mutations_str) != 0) { //So each mutation sequence that is an initial subsequence of an MGS is stored in gsh? Huh! // The quiver is isomorphic to a quiver leading to an maximal green sequence // Update the length list ! (Huh! What's this for!) // 2. For all the quiver sizes attainable with the quiver green_sizes=gsh.getGreenSizes(mutations_str); if (!pe.getAdmittedCVectors().empty()) { for (vi = pe.admittedCVectors.begin(); vi != pe.admittedCVectors.end(); vi++) { if (!belongsTo(*vi, admissibleCVectors)) admissibleCVectors.push_back(*vi); } } std::cout << "admissibleCVecs:" << std::endl; printVectors(admissibleCVectors); if (!pe.getAdmittedGVectors().empty()) { for (vi = pe.admittedGVectors.begin(); vi != pe.admittedGVectors.end(); vi++) { if (!belongsTo(*vi, admissibleGVectors)) admissibleGVectors.push_back(*vi); } } std::cout << "admissibleGVecs:" << std::endl; printVectors(admissibleGVectors); if (!pe.getAdmittedPVectors().empty()) { for (vi = pe.admittedPVectors.begin(); vi != pe.admittedPVectors.end(); vi++) { if (!belongsTo(*vi, admissiblePVectors)) admissiblePVectors.push_back(*vi); } } std::cout << "admissiblePVecs:" << std::endl; printVectors(admissiblePVectors); for(it=green_sizes->begin();it!=green_sizes->end();it++) { // For all the sizes multiplicities mul_map = pe.getMultiplicityMap(); #ifdef DEBUG //pe.printMultiplicityMap(); #endif for(it_mul=mul_map->begin();it_mul != mul_map->end();it_mul++) { pe_size=it_mul->first; n_size=it->first-(*rxi).getMutationsSize()+pe_size;//MGS size mgsInfo[n_size]+=pe.getMultiplicity(it_mul->first)* it->second; //it_mul->first is the length of a mutation sequence from B0 to pe. Hence pe.getMultiplicity(it_mul->first) is literally just its corresponding multiplicity. #ifdef DEBUG std::cout << "Insert MGS of size: " << n_size << " with multiplicity " << "("<<pe.getMultiplicity(it_mul->first) << "*" <<it->second<<") =" << pe.getMultiplicity(it_mul->first) *it->second << std::endl; #endif } n_size=it->first-(*rxi).getMutationsSize()+pe.getMutationsSize(); tmp[n_size] = it->second; } // 3. Update the quiver list mutations_v = pe.getMutations(); gsh.addSizes(mutations_v,tmp);//new mutation sequence and (n_size, it->second) pair } break; } } // if ri went all the way through the end, then the quiver is not // ismomorph to any quiver in already in the list, so we add it //4.Add it if it is not in the cemetary. if(rxi==cemetary.rend()) { c.push_back(pe); #ifdef DEBUG std::cout << "InsertInList: Adding mutation sequence "; pe.printMutations(0); #endif // Insertion done, return 2; return 2; } // No insertion done, return 0 return 0; }