void Haffman::buildTable(Node *root)//кодировка символа { if (root->getLeft()!=NULL) { encode.push_back(0); buildTable(root->getLeft()); } if (root->getRight()!=NULL) { encode.push_back(1); buildTable(root->getRight()); } if( root->getLetter()) catalogue[root->getLetter()]=encode; encode.pop_back(); }
void Hoffman::buildTable(Node *root)//кодировка символа { if (root->left!=NULL) { encode.push_back(0); buildTable(root->left); } if (root->right!=NULL) { encode.push_back(1); buildTable(root->right); } if( root->letter) catalogue[root->letter]=encode; encode.pop_back(); }
/** plist = p1,p2,p3,p4,p5,p6,p7,p8,p9 * * population = 600 * * 9 paper, each paper has 50 person, 9*50 = 540 * session can have all paper, then for build 1 session wit all element * *----------------output------------------- * * Table: s1 * p1p2p3p4p5p6p7p8p9 * */ void test_buildTable_given_9paper_populatoin_is_600_should_create_1_session(void){ pList = linkListNew(&p9); addDataToHead(&pList, &p8); addDataToHead(&pList, &p7); addDataToHead(&pList, &p6); addDataToHead(&pList, &p5); addDataToHead(&pList, &p4); addDataToHead(&pList, &p3); addDataToHead(&pList, &p2); addDataToHead(&pList, &p1); //------------------------------------------------------------------------------------------- table = buildTable( pList, 600); //printfTable( table); TEST_ASSERT_NOT_NULL(S1); TEST_ASSERT_NULL(S2); TEST_ASSERT_EQUAL_PTR(&p1, S1_1->data); TEST_ASSERT_EQUAL_PTR(&p2, S1_2->data); TEST_ASSERT_EQUAL_PTR(&p3, S1_3->data); TEST_ASSERT_EQUAL_PTR(&p4, S1_4->data); TEST_ASSERT_EQUAL_PTR(&p5, S1_5->data); TEST_ASSERT_EQUAL_PTR(&p6, S1_6->data); TEST_ASSERT_EQUAL_PTR(&p7, S1_7->data); TEST_ASSERT_EQUAL_PTR(&p8, S1_8->data); TEST_ASSERT_EQUAL_PTR(&p9, S1_9->data); TEST_ASSERT_NULL(S1_10); }
/** plist = NULL */ void test_buildTable_given_plist_is_NULL_should_create_session_with_nothing(void){ pList = NULL; //------------------------------------------------------------------------------------------- table = buildTable( pList, 50); TEST_ASSERT_NULL(S1); printfTable( table); }
/** plist = p4,p3,p2,p1 * * population = 25 * * each paper has 50 person, population has 25, * means the paper's taker are larger then the total seat in school * this is a violation, to avoid this violation accure, * the assertion is written in sub function of takeSessionFromPaperList() * * Because the assertion is used, un "X" this test will cause system error */ void xtest_buildTable_given_populatoin_is_25_should_system_fail_due_to_assertion(void){ pList = linkListNew(&p1); addDataToHead(&pList, &p2); addDataToHead(&pList, &p3); addDataToHead(&pList, &p4); //------------------------------------------------------------------------------------------- table= buildTable( pList, 25); }
//build LR(1) status int LRBuilder::build(const string& start) { auto& endToken = tokenManager.buildToken("_LR_END", "", LEFT, 0); string& startName = start + "_LR"; auto& production = productionManager.buildProduction(startName, { start },""); int id = productionManager.getProductionID(production);//查找产生式 没有则添加 int endId = tokenManager.getTokenId(endToken.name); LRProduction lrProduction{ id, 0, endId}; //S' -> .s, $ initFirst(); startState = buildState({lrProduction}); buildTable(start); return 0; }
LCA::LCA(const Graph &G, node root) : m_root(root) , m_n(G.numberOfNodes()) , m_len(2 * m_n - 1) , m_rangeJ(Math::floorLog2(m_len)) , m_euler(m_len) , m_representative(G) , m_level(m_len) , m_table(m_len * m_rangeJ) { dfs(G, m_root); buildTable(); }
MateLocation::MateLocation(Unitig *utg) { MateLocationEntry mle; mle.mlePos1.bgn = mle.mlePos1.end = 0; mle.mlePos2.bgn = mle.mlePos2.end = 0; mle.mleFrgID1 = 0; mle.mleFrgID2 = 0; mle.mleUtgID1 = 0; mle.mleUtgID2 = 0; mle.isGrumpy = false; _table.clear(); _table.push_back(mle); _tigLen = utg->getLength(); _numMates = 0; goodGraph = new int32 [_tigLen + 1]; badFwdGraph = new int32 [_tigLen + 1]; badRevGraph = new int32 [_tigLen + 1]; badExternalFwd = new int32 [_tigLen + 1]; badExternalRev = new int32 [_tigLen + 1]; badCompressed = new int32 [_tigLen + 1]; badStretched = new int32 [_tigLen + 1]; badNormal = new int32 [_tigLen + 1]; badAnti = new int32 [_tigLen + 1]; badOuttie = new int32 [_tigLen + 1]; memset(goodGraph, 0, sizeof(int32) * (_tigLen + 1)); memset(badFwdGraph, 0, sizeof(int32) * (_tigLen + 1)); memset(badRevGraph, 0, sizeof(int32) * (_tigLen + 1)); memset(badExternalFwd, 0, sizeof(int32) * (_tigLen + 1)); memset(badExternalRev, 0, sizeof(int32) * (_tigLen + 1)); memset(badCompressed, 0, sizeof(int32) * (_tigLen + 1)); memset(badStretched, 0, sizeof(int32) * (_tigLen + 1)); memset(badNormal, 0, sizeof(int32) * (_tigLen + 1)); memset(badAnti, 0, sizeof(int32) * (_tigLen + 1)); memset(badOuttie, 0, sizeof(int32) * (_tigLen + 1)); buildTable(utg); buildHappinessGraphs(utg); }
/** * Compute the addition of numbers in range 1,000,000 to 5,000,000 for * a fixed number of trials. Using this information we create a histogram * of sorts and output the reults. */ int main (int argc, char **argv) { long len; int i, x; int i1=0; long min = 8000000; long max = 16000000; long delta = 2000000; for (len = min; len <= max; len += delta, i1++) { for (i = 0; i < T; i++) { long sum; gettimeofday(&beforeV, 0); /* begin time */ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &before); sum = 0; for (x = 0; x < len; x++) { sum += x; } gettimeofday(&afterV, 0); /* begin time */ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &after); MStimes[i1][i] = diffTimer (&beforeV, &afterV); NStimes[i1][i] = diffNanoTimer (&before, &after); } } printf ("Table A-5\n"); printf ("n\taverage\t\tmin\tmax\tstdev\t\t#\n"); buildTable(MStimes); printf ("Table A-7\n"); printf ("n\taverage\t\tmin\tmax\tstdev\t\t#\n"); buildTable(NStimes); return 0; }
int main(void) { //We build the tree depending on the string(根据字符串构建二叉树) htTree *codeTree = buildTree("beep boop beer!"); //We build the table depending on the Huffman tree(根据二叉树构建码字表) hlTable *codeTable = buildTable(codeTree); //We encode using the Huffman table(使用码字表编码) encode(codeTable,"beep boop beer!"); //We decode using the Huffman tree(使用二叉树树解码) //We can decode string that only use symbols from the initial string(仅使用初始的字符串中的字符来解码) /* decode(codeTree,"0011111000111"); */ decode(codeTree,"0011111010110001001010101100111110001001"); //Output : 0011 1110 1011 0001 0010 1010 1100 1111 1000 1001 return 0; }
void workHard(int hashSize) { FILE *input1 = fopen("input1.txt", "r"); HashTable *table = createTable(hashSize); int counter = 0; while (!feof(input1)) { char string[1000] = {}; fgets(string, 1000, input1); if (strlen(string) < 1) break; if (counter > 0.7 * hashSize) { destroyHashTable(table); delete table; fclose(input1); //printf("REBUILD!\n"); workHard(2 * hashSize); return; } buildTable(table, string); memset(string, '\0', 1000); counter++; } fclose(input1); //printTable(table); FILE *input2 = fopen("input2.txt", "r"); FILE *output = fopen("output.txt", "w"); while (!feof(input2)) { char string[1000] = {}; fgets(string, 1000, input1); if (strlen(string) < 1) break; if (isExists(table, string)) { fputs(string, output); } memset(string, '\0', 1000); } destroyHashTable(table); delete table; fclose(input2); fclose(output); }
/** plist = p1,p2,p3,p4 * * population = 100 * * each paper has 50 person, 1 session can have 2 paper * so create 2 session * *----------------output------------------- * * Table: s1 s2 * p1p2 p3p4 * */ void test_buildTable_given_populatoin_is_100_should_create_2_session(void){ pList = linkListNew(&p4); addDataToHead(&pList, &p3); addDataToHead(&pList, &p2); addDataToHead(&pList, &p1); //------------------------------------------------------------------------------------------- table = buildTable( pList, 100); //printfTable( table); TEST_ASSERT_NOT_NULL(S1); TEST_ASSERT_NOT_NULL(S2); TEST_ASSERT_NULL(S3); TEST_ASSERT_EQUAL_PTR(&p1, S1_1->data); TEST_ASSERT_EQUAL_PTR(&p2, S1_2->data); TEST_ASSERT_EQUAL_PTR(&p3, S2_1->data); TEST_ASSERT_EQUAL_PTR(&p4, S2_2->data); TEST_ASSERT_NULL(S1_3); TEST_ASSERT_NULL(S2_3); }
void ossimHistogramRemapper::setStretchMode(StretchMode mode, bool rebuildTable) { if (theStretchMode != mode) { theStretchMode = mode; if (rebuildTable) { buildTable(); // Check for internal bypass. verifyEnabled(); // Clear the dirty flag. theDirtyFlag = false; } else { theDirtyFlag = true; } } }
ossimRefPtr<ossimImageData> ossimHistogramRemapper::getTile( const ossimIrect& tile_rect, ossim_uint32 resLevel) { #if 0 /* Please leave for serious debug. (drb) */ cout << "\ntheEnableFlag: " << theEnableFlag << "\ntheBypassFlag: " << theBypassFlag << "\ntheDirtyFlag: " << theDirtyFlag << endl; #endif ossimRefPtr<ossimImageData> result = 0; if (theEnableFlag && theDirtyFlag) // Enabled and dirty. { // Always rebuild table if dirty. buildTable(); // Check for internal bypass. verifyEnabled(); // Always clear the dirty flag. theDirtyFlag = false; } if (!theBypassFlag) // Not bypassed... { // Base handles the rest... result = ossimTableRemapper::getTile(tile_rect, resLevel); } else if (theInputConnection) { // Fetch tile from pointer from the input source. result = theInputConnection->getTile(tile_rect, resLevel); } return result; }
void ReadKkit::undump( const vector< string >& args) { if ( args[1] == "kpool" ) buildPool( args ); else if ( args[1] == "kreac" ) buildReac( args ); else if ( args[1] == "kenz" ) buildEnz( args ); else if ( args[1] == "text" ) buildText( args ); else if ( args[1] == "xplot" ) buildPlot( args ); else if ( args[1] == "xgraph" ) buildGraph( args ); else if ( args[1] == "group" ) buildGroup( args ); else if ( args[1] == "geometry" ) buildGeometry( args ); else if ( args[1] == "stim" ) buildStim( args ); else if ( args[1] == "xcoredraw" ) ; else if ( args[1] == "xtree" ) ; else if ( args[1] == "xtext" ) ; else if ( args[1] == "doqcsinfo" ) ; else if ( args[1] == "kchan" ) buildChan( args ); else if ( args[1] == "xtab" ) buildTable( args ); else cout << "ReadKkit::undump: Do not know how to build '" << args[1] << "'\n"; }
Scene* tableScene(float w, float h) { char tmpStr[30]; #ifdef _DBG printf("Setting up the table scene\n"); #endif Camera* theCamera = new Camera("mainC"); theCamera->setZPlanes(1.0f, 100.0f); theCamera->setEye(8.0f, -5.0f, 15.0f); theCamera->setUp(0.0f, 1.0f, 0.0f); theCamera->setCenter(8.0f, -5.0f, 0.0f); theCamera->setAspectRatio(w/h); theCamera->setAngle(50.0f); theCamera->setManipulator(new VManipulator); theCamera->setZCenter(20.0f); /* Codigo para a sala em si */ Material* walls = new Material(0.3f, 0.3f, 0.3f); walls->setSpecular(0.2f, 0.2f, 0.2f); walls->setShininess(50); Entity* room = new Entity("room", new Cube(20.0, 0.0f, 40.0f), walls); Transform* roomT = new Transform("roomT"); roomT->translate(0.0f, -7.5f, 0.0f); roomT->addNode(room); Texture* wood = new Texture("../images/teakwood.bmp"); wood->setPlane(S, 1.0f, 0.0f, 0.0f, 0.0f, false); wood->setPlane(T, 0.0f, 1.0f, 0.0f, 0.0f, false); Material* greyPlastic = new Material(0.2f, 0.2f, 0.2f); greyPlastic->setSpecular(0.5f, 0.5f, 0.5f); greyPlastic->setShininess(90); Entity* ball = new Entity("ball", new Sphere(1.0f), greyPlastic); /* Codigo para a luz comprida */ Transform* lightPos = buildBigLight(); /* a mesa */ Transform* tablePos = buildTable(greyPlastic); /* cadeiras */ Transform* chairCont = buildChair(wood, greyPlastic); Transform** chairPos = new Transform*[5]; for (int i=0; i<5; i++) { sprintf(tmpStr, "chairPos%d", i+1); chairPos[i] = new Transform(tmpStr); } chairPos[0]->rotate(90, 0.0f, 1.0f, 0.0f); chairPos[0]->translate(-3.0f, 0.0f, 5.0f); chairPos[1]->rotate(100, 0.0f, 1.0f, 0.0f); chairPos[1]->translate(3.0f, 0.0f, 7.0f); chairPos[2]->rotate(80, 0.0f, 1.0f, 0.0f); chairPos[2]->translate(5.0f, 0.0, 0.0f); chairPos[3]->rotate(95, 0.0f, 1.0f, 0.0f); chairPos[3]->translate(-2.0f, 0.0f, -3.0f); chairPos[4]->rotate(120, 0.0, 1.0f, 0.0f); chairPos[4]->translate(6.0f, 0.0f, 5.0f); for (int i=0; i<5; i++) chairPos[i]->addNode(chairCont); /* Coelho sobre uma cadeira */ Entity* bunny = new Entity("bunny", new Mesh("bunny.msh"), greyPlastic); Transform* bunnyT = new Transform("bunnyT"); bunnyT->translate(0.5f, -5.2f, -0.3f); bunnyT->addNode(bunny); chairPos[4]->addNode(bunnyT); Transform* lampPos = buildLamp(); chairPos[2]->addNode(lampPos); /* Montando a cena */ Scene* theScene = new Scene("mainScene"); theScene->setClearColor(0.0f, 0.0f, 0.0f, 1.0f); theScene->addNode(theCamera); theScene->activateCamera("mainC"); theScene->addNode(roomT); //theScene->addNode(ball); theScene->addNode(lightPos); theScene->addNode(tablePos); for (int i=0; i<5; i++) theScene->addNode(chairPos[i]); //Fog! theScene->enableFog(true); theScene->setFogColor(0.2f, 0.2f, 0.2f, 1.0f); theScene->setFogMode(fog_linear); theScene->setFogLim(5.0, 40.0); return theScene; }
MateLocation::MateLocation(UnitigVector &unitigs, Unitig *utg) { MateLocationEntry mle; mle.mlePos1.bgn = mle.mlePos1.end = 0; mle.mlePos2.bgn = mle.mlePos2.end = 0; mle.mleFrgID1 = 0; mle.mleFrgID2 = 0; mle.mleUtgID1 = 0; mle.mleUtgID2 = 0; mle.isGrumpy = false; _table.clear(); _table.push_back(mle); _tig = utg; _tigLen = utg->getLength(); _numMates = 0; good = new int32 [_tigLen + 1]; badFwd = new int32 [_tigLen + 1]; badRev = new int32 [_tigLen + 1]; badExternalFwd = new int32 [_tigLen + 1]; badExternalRev = new int32 [_tigLen + 1]; badCompressed = new int32 [_tigLen + 1]; badStretched = new int32 [_tigLen + 1]; badNormal = new int32 [_tigLen + 1]; badAnti = new int32 [_tigLen + 1]; badOuttie = new int32 [_tigLen + 1]; memset(good, 0, sizeof(int32) * (_tigLen + 1)); memset(badFwd, 0, sizeof(int32) * (_tigLen + 1)); memset(badRev, 0, sizeof(int32) * (_tigLen + 1)); memset(badExternalFwd, 0, sizeof(int32) * (_tigLen + 1)); memset(badExternalRev, 0, sizeof(int32) * (_tigLen + 1)); memset(badCompressed, 0, sizeof(int32) * (_tigLen + 1)); memset(badStretched, 0, sizeof(int32) * (_tigLen + 1)); memset(badNormal, 0, sizeof(int32) * (_tigLen + 1)); memset(badAnti, 0, sizeof(int32) * (_tigLen + 1)); memset(badOuttie, 0, sizeof(int32) * (_tigLen + 1)); nunmated = 0; ngood[0] = ngood[1] = ngood[2] = 0; nbadFwd[0] = nbadFwd[1] = nbadFwd[2] = 0; nbadRev[0] = nbadRev[1] = nbadRev[2] = 0; ngoodExternalFwd[0] = ngoodExternalFwd[1] = ngoodExternalFwd[2] = 0; ngoodExternalRev[0] = ngoodExternalRev[1] = ngoodExternalRev[2] = 0; nbadExternalFwd[0] = nbadExternalFwd[1] = nbadExternalFwd[2] = 0; nbadExternalRev[0] = nbadExternalRev[1] = nbadExternalRev[2] = 0; nbadCompressed[0] = nbadCompressed[1] = nbadCompressed[2] = 0; nbadStretched[0] = nbadStretched[1] = nbadStretched[2] = 0; nbadNormal[0] = nbadNormal[1] = nbadNormal[2] = 0; nbadAnti[0] = nbadAnti[1] = nbadAnti[2] = 0; nbadOuttie[0] = nbadOuttie[1] = nbadOuttie[2] = 0; buildTable(); buildHappinessGraphs(unitigs); }
int main(int argc, char *argv[]) { QCoreApplication application(argc, argv); application.addLibraryPath("."); QTextStream out(stdout, QIODevice::WriteOnly); if (argc > 1) { QString databaseURL; QString username; QString passwd; QString arguments; QString dbServer = QString::null; for (int counter = 1; counter < argc; counter++) { QString arguments(argv[counter]); if (arguments.startsWith("-databaseURL=", Qt::CaseInsensitive)) databaseURL = arguments.right(arguments.length() - 13); else if (arguments.startsWith("-username="******"-passwd=", Qt::CaseInsensitive)) passwd = arguments.right(arguments.length() - 8); else if (arguments.startsWith("-dbengine=", Qt::CaseInsensitive)) dbServer = arguments.right(arguments.length() - 10); } if ( (databaseURL != "") && (username != "") && (passwd != "") ) { QSqlDatabase db; QString protocol = QString::null; QString server = QString::null; QString database = QString::null; QString port = QString::null; // Note: parseDatabaseURL returns a default port of 5432 (Default Postgresql port) // is this a bug or a feature ? parseDatabaseURL(databaseURL, protocol, server, database, port); // treat odbc connections as a special case if ( protocol == "odbc") { if ( dbServer == QString::null ) { out << " database URL = " << databaseURL << endl; out << "Protocol=" << protocol << ", Host=" << server << ", Database=" << database << ", port=" << port << endl; out << "\"--dbengine=\" parameter required when url protocol is odbc" << endl; exit(EXIT_ERROR_MISSING_DB_ENGINE); } if (! isValidProtocol(dbServer, false) ) { out << "Unrecognised database server: [--dbengine=" << dbServer << "]" << endl; out << "Protocol=" << protocol << ", Host=" << server << ", Database=" << database << ", port=" << port << endl; exit(EXIT_ERROR_DB_ENGINE); } } // Open the Database Driver db = databaseFromURL( databaseURL ); if (!db.isValid()) { out << " database URL = " << databaseURL << endl; out << "Protocol=" << protocol << ", Host=" << server << ", Database=" << database << ", port=" << port << endl; out << "Could not load the specified database driver." << endl; exit(EXIT_ERROR_DB_DRIVER); } // Try to connect to the Database db.setUserName(username); db.setPassword(passwd); if (!db.open()) { out << "Protocol=" << protocol << ", Host=" << db.hostName() << ", Database=" << db.databaseName() << ", port=" << db.port() << endl; out << "Could not log into database. System Error: " << db.lastError().text() << endl; exit(EXIT_ERROR_DB_LOGIN); } if ( ! buildTable(db, out, dbServer) ) exit(EXIT_ERROR_DB_TABLE_BUILD); } else if (databaseURL == "") { out << "You must specify a Database URL by using the -databaseURL= parameter." << endl; exit(EXIT_ERROR_MISSING_URL); } else if (username == "") { out << "You must specify a Database Username by using the -username= parameter." << endl; exit(EXIT_ERROR_MISSING_USERNAME); } else if (passwd == "") { out << "You must specify a Database Password by using the -passwd= parameter." << endl; exit(EXIT_ERROR_MISSING_PASSWORD); } } else { out << "Usage: bldtbls -databaseURL='$' -username='******' -passwd='$' [-dbengine='$']" << endl; exit(EXIT_ERROR_BAD_ARGS); } return EXIT_SUCCESS; }
////-------------------------------------------------------------------------- //// HashTable() //// Constractor HashTable::HashTable() { buildTable(); }
//if shouldBuild dirty bit is set, combine c-scan lists into one list and buildTable //use headposition and table build to make best path //turn dirty shouldBuild dirty bit off //dispatch first guy in path //set new head position static int optimal_dispatch(struct request_queue *q, int force) { int size = 0, ndx = 1; long cost1, cost2; struct list_head *entry; struct requestList *scan; struct optimal_data *nd = q->elevator->elevator_data; if(nd->shouldBuild){ //put everything in my cscan list into an array of requests //in cscan order entry = &nd->arrival_queue; while(((entry = entry->next)!=&nd->arrival_queue)&&size<nd->max_requests){ nd->mylist[size] = list_entry_rq(entry); size++; } if(size == 0){ nd->dispatchSize = 0; nd->currentNdx = 0; return 0; } //might be redundant if(size > nd->max_requests) size = nd->max_requests; buildTable(nd->mylist, size, nd->C); cost1 = ((size-1) + 1) * distance(blk_rq_pos(&nd->headpos), blk_rq_pos(nd->mylist[0])) + nd->C[0][size-1][0].cost; cost2 = ((size-1) + 1) * distance(blk_rq_pos(&nd->headpos), blk_rq_pos(nd->mylist[size-1])) + nd->C[0][size-1][1].cost; if(cost1 < cost2){ nd->dispatch_head[0] = nd->mylist[0]; //for each item in C[0][size-1][0]'s path, add to dispatch_head scan = nd->C[0][size-1][0].head; while(scan != NULL && scan->data != NULL){ nd->dispatch_head[ndx] = scan->data; ndx++; scan = scan->next; } } else{ nd->dispatch_head[0] = nd->mylist[size-1]; scan = nd->C[0][size-1][1].head; while(scan != NULL && scan->data != NULL){ nd->dispatch_head[ndx] = scan->data; ndx++; scan = scan->next; } } nd->dispatchSize = size; nd->currentNdx = 0; nd->shouldBuild = 0; } /* if (!list_empty(&nd->arrival_queue)) { struct request *rq; rq = list_entry(nd->arrival_queue.next, struct request, queuelist); nd->headpos.__sector =rq_end_sector(rq); list_del_init(&rq->queuelist); elv_dispatch_add_tail(q, rq); nd->currentNdx++; return 1; } */ if(nd->currentNdx < nd->dispatchSize){ struct request *rq; rq = nd->dispatch_head[nd->currentNdx]; nd->headpos.__sector = rq_end_sector(rq); list_del_init(&rq->queuelist); elv_dispatch_add_tail(q, rq); nd->currentNdx++; return 1; } return 0; }
int main(int argc, char *argv[]) { QCoreApplication app(argc,argv); // check input args QStringList inputArgs = app.arguments(); if(inputArgs.size() != 2) { badInput(); return -1; } // open osmscout map osmscout::DatabaseParameter map_param; osmscout::Database map(map_param); if(!map.Open(inputArgs[1].toStdString())) { qDebug() << "ERROR: Failed to open osmscout map"; return -1; } osmscout::TypeConfig * typeConfig = map.GetTypeConfig(); osmscout::TypeSet typeSet; setTypesForAdminRegions(typeConfig,typeSet); // GeoBoundingBox tempbbox; // tempbbox.minLon = -83.3203; tempbbox.maxLon = -82.9688; // tempbbox.minLat = 42.1875; tempbbox.maxLat = 42.3633; //// tempbbox.minLon -= 1; tempbbox.maxLon += 1; //// tempbbox.minLat -= 1; tempbbox.maxLat += 1; // create search database Kompex::SQLiteDatabase * database; Kompex::SQLiteStatement * stmt; QString db_file_path = app.applicationDirPath()+"/searchdb.sqlite"; QFile db_file(db_file_path); if(db_file.exists()) { if(!db_file.remove()) { qDebug() << "ERROR: searchdb.sqlite exists and " "could not be deleted"; return -1; } } try { database = new Kompex::SQLiteDatabase("searchdb.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,0); stmt = new Kompex::SQLiteStatement(database); stmt->SqlStatement("CREATE TABLE name_lookup(" "name_id INTEGER PRIMARY KEY NOT NULL," "name_lookup TEXT NOT NULL UNIQUE);"); stmt->SqlStatement("CREATE TABLE admin_regions(" "id INTEGER PRIMARY KEY NOT NULL," "node_offsets BLOB," "way_offsets BLOB," "area_offsets BLOB" ");"); stmt->SqlStatement("CREATE TABLE streets(" "id INTEGER PRIMARY KEY NOT NULL," "node_offsets BLOB," "way_offsets BLOB," "area_offsets BLOB" ");"); stmt->SqlStatement("CREATE TABLE pois(" "id INTEGER PRIMARY KEY NOT NULL," "node_offsets BLOB," "way_offsets BLOB," "area_offsets BLOB" ");"); } catch(Kompex::SQLiteException &exception) { qDebug() << "ERROR: SQLite exception creating database:" << QString::fromStdString(exception.GetString()); return -1; } // build a tile list for the dataset // // world bbox // GeoBoundingBox bbox_world; // bbox_world.minLon = -180.0; bbox_world.maxLon = 180.0; // bbox_world.minLat = -90.0; bbox_world.maxLat = 90.0; // map data bbox GeoBoundingBox bbox_map; map.GetBoundingBox(bbox_map.minLat,bbox_map.minLon, bbox_map.maxLat,bbox_map.maxLon); // generate tile list std::vector<Tile*> list_tiles; buildTileList(bbox_map,list_tiles); #ifdef DEBUG_WITH_OSG return displayTiles(bbox_map,list_tiles); #endif // [name_id] [name_key] int32_t name_id=1; boost::unordered_map<std::string,int32_t> table_names; // build database tables bool opOk=false; // admin_regions qDebug() << "INFO: Building admin_regions table..."; setTypesForAdminRegions(typeConfig,typeSet); opOk = buildTable(stmt,name_id,table_names,"admin_regions", list_tiles,map,typeSet,false,true,true); if(opOk) { qDebug() << "INFO: Finished building admin_regions table"; } else { qDebug() << "ERROR: Failed to build admin_regions table"; return -1; } // streets qDebug() << "INFO: Building streets table..."; setTypesForStreets(typeConfig,typeSet); opOk = buildTable(stmt,name_id,table_names,"streets", list_tiles,map,typeSet,false,false,false); if(opOk) { qDebug() << "INFO: Finished building streets table"; } else { qDebug() << "ERROR: Failed to build streets table"; return -1; } // pois qDebug() << "INFO: Building pois table..."; setTypesForPOIs(typeConfig,typeSet); opOk = buildTable(stmt,name_id,table_names,"pois", list_tiles,map,typeSet,false,false,false); if(opOk) { qDebug() << "INFO: Finished building pois table"; } else { qDebug() << "ERROR: Failed to build pois table"; return -1; } // build name_lookup table qDebug() << "INFO: Building name_lookup table..."; opOk = buildNameLookupTable(stmt,table_names); if(opOk) { qDebug() << "INFO: Finished building name_lookup table"; } else { qDebug() << "ERROR: Failed to build name_lookup table"; return -1; } // vacuum to minimize db try { stmt->SqlStatement("VACUUM;"); } catch(Kompex::SQLiteException &exception) { qDebug() << "ERROR: SQLite exception vacuuming:" << QString::fromStdString(exception.GetString()); return -1; } // clean up for(size_t i=0; i < list_tiles.size(); i++) { delete list_tiles[i]; } list_tiles.clear(); delete stmt; delete database; // // ### debug // std::map<int64_t,std::string> table_count_names; // boost::unordered_map<std::string,qint64>::iterator it; // for(it = table_names.begin(); it != table_names.end(); ++it) { // std::map<int64_t,int64_t>::iterator d_it; // d_it = g_table_nameid_count.find(it->second); // std::pair<int64_t,std::string> data; // data.first = d_it->second; // data.second = it->first; // table_count_names.insert(data); // } // std::map<int64_t,std::string>::iterator c_it; // for(c_it = table_count_names.begin(); // c_it != table_count_names.end(); ++c_it) { // qDebug() << QString::fromStdString(c_it->second) << ":" << c_it->first; // } // // debug // boost::unordered_map<std::string,qint64>::iterator it; // for(it = table_names.begin(); it != table_names.end(); ++it) // { // qDebug() << it->second << ": " << QString::fromStdString(it->first); // } }