void StlAdvancedFeaturesExample::queue_stack() { int i; if ( explicit_txn) dbstl::begin_txn(0, penv); // test whether db_vector works with std::queue, // std::priority_queue and std::stack cout<<"\ndb_vector working with std::queue\n"; // std::queue test intvec_t quev(quedb, penv); quev.clear(); std::queue<ptint, intvec_t> intq(quev); std::queue<ptint> sintq; check_expr(intq.empty()); check_expr(intq.size() == 0); for (i = 0; i < 100; i++) { intq.push(ptint(i)); sintq.push(i); check_expr(intq.front() == 0); check_expr(intq.back() == i); } check_expr(intq.size() == 100); for (i = 0; i < 100; i++) { check_expr(intq.front() == i); check_expr(intq.back() == 99); check_expr(intq.front() == sintq.front()); check_expr(sintq.back() == intq.back()); sintq.pop(); intq.pop(); } check_expr(intq.size() == 0); check_expr(intq.empty()); quev.clear(); // std::priority_queue test cout<<"\ndb_vector working with std::priority_queue\n"; std::vector<ptint> squev; intvec_t pquev(pquedb, penv); pquev.clear(); std::priority_queue<ptint, intvec_t, ptintless_ft> intpq(ptintless, pquev); std::priority_queue<ptint, vector<ptint>, ptintless_ft> sintpq(ptintless, squev); check_expr(intpq.empty()); check_expr(intpq.size() == 0); ptint tmppq, tmppq1; set<ptint> ptintset; for (i = 0; i < 100; i++) { for (;;) {// avoid duplicate tmppq = rand(); if (ptintset.count(tmppq) == 0) { intpq.push(tmppq); sintpq.push(tmppq); ptintset.insert(tmppq); break; } } } check_expr(intpq.empty() == false); check_expr(intpq.size() == 100); for (i = 0; i < 100; i++) { tmppq = intpq.top(); tmppq1 = sintpq.top(); if (i == 98 && tmppq != tmppq1) { tmppq = intpq.top(); } if (i < 98) check_expr(tmppq == tmppq1); if (i == 97) intpq.pop(); else intpq.pop(); sintpq.pop(); } check_expr(intpq.empty()); check_expr(intpq.size() == 0); // std::stack test cout<<"\ndb_vector working with std::stack\n"; std::stack<ptint, intvec_t> intstk(quev); std::stack<ptint> sintstk; check_expr(intstk.size() == 0); check_expr(intstk.empty()); for (i = 0; i < 100; i++) { intstk.push(ptint(i)); sintstk.push(ptint(i)); check_expr(intstk.top() == i); check_expr(intstk.size() == (size_t)i + 1); } for (i = 99; i >= 0; i--) { check_expr(intstk.top() == ptint(i)); check_expr(intstk.top() == sintstk.top()); sintstk.pop(); intstk.pop(); check_expr(intstk.size() == (size_t)i); } check_expr(intstk.size() == 0); check_expr(intstk.empty()); // Vector with no handles specified. ptint_vector simple_vct(10); vector<ptint> ssvct(10); for (i = 0; i < 10; i++) { simple_vct[i] = ptint(i); ssvct[i] = ptint(i); } check_expr(is_equal(simple_vct, ssvct)); if ( explicit_txn) dbstl::commit_txn(penv); return; } // queue_stack
// number of decimal digits to which x and y agree int digits(const doubledouble& x, const doubledouble& y){ doubledouble diff=fabs(x-y); if (diff.h()==0.0) return 32; int d=-intq(floor((0.4*log((diff/fabs(x))))).h()); return d<32?d:32; }