Search Results

Search found 3 results on 1 pages for 'kungi'.

Page 1/1 | 1 

  • Creating a fixed length output string with sprintf containing floats

    - by Kungi
    Hi, I'm trying to create a file which has the following structure: - Each line has 32 bytes - Each line looks like this format string: "%10i %3.7f %3.7f\n" My Problem is the following: When i have a negative floating point numbers the line gets longer by one or even two characters because the - sign does not count to the "%3.7f". Is there any way to do this more nicely than this? if( node->lng > 0 && node->lat > 0 ) { sprintf( osm_node_repr, "%10i %3.7f %3.7f\n", node->id, node->lng, node->lat ); } else if (node->lng > 0 && node->lat < 0) { sprintf( osm_node_repr, "%10i %3.7f %3.6f\n", node->id, node->lng, node->lat ); } else if (node->lng < 0 && node->lat > 0) { sprintf( osm_node_repr, "%10i %3.6f %3.7f\n", node->id, node->lng, node->lat ); } else if ( node->lng < 0 && node->lat < 0 ) { sprintf( osm_node_repr, "%10i %3.6f %3.6f\n", node->id, node->lng, node->lat ); } Thanks for your Answers, Andreas

    Read the article

  • Insert MANY key value pairs fast into berkeley db with hash access

    - by Kungi
    Hi, i'm trying to build a hash with berkeley db, which shall contain many tuples (approx 18GB of key value pairs), but in all my tests the performance of the insert operations degrades drastically over time. I've written this script to test the performance: #include<iostream> #include<db_cxx.h> #include<ctime> #define MILLION 1000000 int main () { long long a = 0; long long b = 0; int passes = 0; int i = 0; u_int32_t flags = DB_CREATE; Db* dbp = new Db(NULL,0); dbp->set_cachesize( 0, 1024 * 1024 * 1024, 1 ); int ret = dbp->open( NULL, "test.db", NULL, DB_HASH, flags, 0); time_t time1 = time(NULL); while ( passes < 100 ) { while( i < MILLION ) { Dbt key( &a, sizeof(long long) ); Dbt data( &b, sizeof(long long) ); dbp->put( NULL, &key, &data, 0); a++; b++; i++; } DbEnv* dbep = dbp->get_env(); int tmp; dbep->memp_trickle( 50, &tmp ); i=0; passes++; std::cout << "Inserted one million --> pass: " << passes << " took: " << time(NULL) - time1 << "sec" << std::endl; time1 = time(NULL); } } Perhaps you can tell me why after some time the "put" operation takes increasingly longer and maybe how to fix this. Thanks for your help, Andreas

    Read the article

1