inline void loop::write(handler::base &h) { int r; DSCRPTR fd = h.fd(); EIO_TRACE("write: fd = %d\n", fd); switch((r = h.on_write(p()))) { case handler::base::keep: { EIO_TRACE("write: %d: process again\n", fd); task::io t(&h, task::io::WRITE_AGAIN); que().mpush(t); } break; case handler::base::write_again: { EIO_TRACE("write: %d: back to poller\n", fd); r = p().retach(fd, poller::EV_WRITE); ASSERT(r >= 0); } break; case handler::base::read_again: { EIO_TRACE("write: %d: back to poller\n", fd); p().retach(fd, poller::EV_READ); } break; case handler::base::nop: { EIO_TRACE("write: %d: wait next retach\n", fd); } break; case handler::base::destroy: default: { ASSERT(r == handler::base::destroy); TRACE("write: %d: close %d\n", fd, r); task::io t(&h, task::io::CLOSE); que().mpush(t); } break; } }
int main() { // Test the explicit deduction guides { // queue(const Container&, const Alloc&); // The '45' is not an allocator std::queue que(std::list<int>{1,2,3}, 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'queue'}} } { // queue(const queue&, const Alloc&); // The '45' is not an allocator std::queue<int> source; std::queue que(source, 45); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'queue'}} } // Test the implicit deduction guides { // queue (allocator &) std::queue que((std::allocator<int>())); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'queue'}} // Note: The extra parens are necessary, since otherwise clang decides it is a function declaration. // Also, we can't use {} instead of parens, because that constructs a // stack<allocator<int>, allocator<allocator<int>>> } }
inline void loop::read(handler::base &h, poller::event &e) { int r; DSCRPTR fd = h.fd(); EIO_TRACE("read: fd = %d\n", fd); switch((r = h.on_read(*this, e))) { case handler::base::keep: { EIO_TRACE("read: %d: process again\n", fd); task::io t(&h, e, task::io::READ_AGAIN); que().mpush(t); } break; case handler::base::read_again: { EIO_TRACE("read: %d,%d,%d: back to poller\n", fd, h.type(), util::syscall::error_no()); r = p().retach(fd, poller::EV_READ); ASSERT(r >= 0); } break; case handler::base::write_again: { EIO_TRACE("read: %d: back to poller\n", fd); p().retach(fd, poller::EV_WRITE); } break; case handler::base::nop: { EIO_TRACE("read: %d: wait next retach\n", fd); } break; case handler::base::destroy: default: { ASSERT(r == handler::base::destroy); TRACE("read: %d: close %d\n", fd, r); task::io t(&h, task::io::CLOSE); que().mpush(t); } break; } }
int que(int a,int b,int l,int r,int val) { if(a==l && b==r)return sum[val]; int q=(l+r)>>1; if(q>=b)return que(a,b,l,q,val<<1); if(q<=a)return que(a,b,q,r,val<<1|1); return que(a,q,l,q,val<<1)+que(q,b,q,r,val<<1|1); }
int main(int, char**) { // Test the explicit deduction guides { std::list<int> l{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::queue que(l); static_assert(std::is_same_v<decltype(que), std::queue<int, std::list<int>>>, ""); assert(que.size() == l.size()); assert(que.back() == l.back()); } { std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; std::queue que(l, test_allocator<long>(0,2)); // different allocator static_assert(std::is_same_v<decltype(que)::container_type, std::list<long, test_allocator<long>>>, ""); static_assert(std::is_same_v<decltype(que)::value_type, long>, ""); assert(que.size() == 10); assert(que.back() == 19); // I'd like to assert that we've gotten the right allocator in the queue, but // I don't know how to get at the underlying container. } // Test the implicit deduction guides { // We don't expect this one to work - no way to implicitly get value_type // std::queue que(std::allocator<int>()); // queue (allocator &) } { std::queue<A> source; std::queue que(source); // queue(queue &) static_assert(std::is_same_v<decltype(que)::value_type, A>, ""); static_assert(std::is_same_v<decltype(que)::container_type, std::deque<A>>, ""); assert(que.size() == 0); } { // This one is odd - you can pass an allocator in to use, but the allocator // has to match the type of the one used by the underlying container typedef short T; typedef test_allocator<T> A; typedef std::deque<T, A> C; C c{0,1,2,3}; std::queue<T, C> source(c); std::queue que(source, A(2)); // queue(queue &, allocator) static_assert(std::is_same_v<decltype(que)::value_type, T>, ""); static_assert(std::is_same_v<decltype(que)::container_type, C>, ""); assert(que.size() == 4); assert(que.back() == 3); } return 0; }
int main() { scanf("%d%d", &n, &q); for(int i = 1, x; i <= n; ++i) { scanf("%d", &x); for(int j = 2; j <= x / j; ++j) if(x % j == 0) { a[i][++a[i][0]] = j; while(x % j == 0) x /= j; } if(x > 1) a[i][++a[i][0]] = x; } for(int i = 1, x; i <= q; ++i) { scanf("%d", &x); if(!vis[x]) { vis[x] = 1; add(x, 1); ++num; ans += que(x); } else { vis[x] = 0; ans -= que(x); --num; add(x, -1); } printf("%lld\n", ans); } return 0; }
inline void loop::poll() { int n_ev; task::io t; /* TODO: add task throughput control */ while (que().pop(t)) { t(*this); } poller::event occur[maxfd()]; if ((n_ev = p().wait(occur, maxfd(), timeout())) < 0) { if (p().error_again()) { return; } TRACE("poller::wait: %d", p().error_no()); return; } for (int i = 0; i < n_ev; i++) { read(occur[i]); } }
int main() { int t; scanf("%d",&t); for(int i=1;i<=t;i++) { printf("Case %d:\n",i); int n; scanf("%d",&n); build(1,n+1,1); char s[10]; while(scanf("%s",s)) { if('E'==s[0])break; int a,b; scanf("%d%d",&a,&b); if('Q'==s[0]){printf("%d\n",que(a,b+1,1,n+1,1));} else if('A'==s[0]){add(a,b,1,n+1,1);} else{add(a,-b,1,n+1,1);} } } return 0; }
static void HandleQueues() { int ilRc = RC_SUCCESS; /* Return code */ int ilBreakOut = FALSE; do { ilRc = que(QUE_GETBIG,0,mod_id,PRIORITY_3,igItemLen,(char *)&prgItem); /* depending on the size of the received item */ /* a realloc could be made by the que function */ /* so do never forget to set event pointer !!! */ prgEvent = (EVENT *) prgItem->text; if( ilRc == RC_SUCCESS ) { /* Acknowledge the item */ ilRc = que(QUE_ACK,0,mod_id,0,0,NULL); if( ilRc != RC_SUCCESS ) { /* handle que_ack error */ HandleQueErr(ilRc); } /* fi */ switch( prgEvent->command ) { case HSB_STANDBY : ctrl_sta = prgEvent->command; break; case HSB_COMING_UP : ctrl_sta = prgEvent->command; break; case HSB_ACTIVE : ctrl_sta = prgEvent->command; ilBreakOut = TRUE; break; case HSB_ACT_TO_SBY : ctrl_sta = prgEvent->command; break; case HSB_DOWN : /* whole system shutdown - do not further use que(), send_message() or timsch() ! */ ctrl_sta = prgEvent->command; Terminate(1); break; case HSB_STANDALONE : ctrl_sta = prgEvent->command; ResetDBCounter(); ilBreakOut = TRUE; break; case REMOTE_DB : /* ctrl_sta is checked inside */ HandleRemoteDB(prgEvent); break; case SHUTDOWN : Terminate(1); break; case RESET : ilRc = Reset(); break; case EVENT_DATA : dbg(TRACE,"HandleQueues: wrong hsb status <%d>",ctrl_sta); DebugPrintItem(TRACE,prgItem); DebugPrintEvent(TRACE,prgEvent); break; case TRACE_ON : dbg_handle_debug(prgEvent->command); break; case TRACE_OFF : dbg_handle_debug(prgEvent->command); break; default : dbg(TRACE,"HandleQueues: unknown event"); DebugPrintItem(TRACE,prgItem); DebugPrintEvent(TRACE,prgEvent); break; } /* end switch */ } else { /* Handle queuing errors */ HandleQueErr(ilRc); } /* end else */ } while (ilBreakOut == FALSE); ilRc = Init_Process(); if(ilRc != RC_SUCCESS) { dbg(TRACE,"InitDemhdl: init failed!"); } } /* end of HandleQueues */
/// Constructor. ibis::jRange::jRange(const ibis::part& partr, const ibis::part& parts, const ibis::column& colr, const ibis::column& cols, double delta1, double delta2, const ibis::qExpr* condr, const ibis::qExpr* conds, const ibis::selectClause* sel, const ibis::fromClause* frm, const char* desc) : sel_(sel ? new ibis::selectClause(*sel) : 0), frm_(frm ? new ibis::fromClause(*frm) : 0), partr_(partr), parts_(parts), colr_(colr), cols_(cols), delta1_(delta1), delta2_(delta2), orderr_(0), orders_(0), valr_(0), vals_(0), nrows(-1) { if (desc == 0 || *desc == 0) { // build a description string std::ostringstream oss; oss << "From " << partr.name() << " Join " << parts.name() << " On " << delta1 << " <= " << partr.name() << '.' << colr.name() << " - " << parts.name() << '.' << cols.name() << " <= " << delta2 << " Where ..."; desc_ = oss.str(); } else { desc_ = desc; } int ierr; if (condr != 0) { ibis::countQuery que(&partr); ierr = que.setWhereClause(condr); if (ierr < 0) { LOGGER(ibis::gVerbose > 1) << "Warning -- jRange(" << desc_ << ") could apply " << condr << " on partition " << partr.name() << ", ierr = " << ierr; throw "jRange::ctor failed to apply conditions on partr" IBIS_FILE_LINE; } ierr = que.evaluate(); if (ierr < 0) { LOGGER(ibis::gVerbose > 1) << "Warning -- jRange(" << desc_ << ") could not evaluate " << que.getWhereClause() << " on partition " << partr.name() << ", ierr = " << ierr; throw "jRange::ctor failed to evaluate constraints on partr" IBIS_FILE_LINE; } maskr_.copy(*que.getHitVector()); } else { colr.getNullMask(maskr_); } if (conds != 0) { ibis::countQuery que(&parts); ierr = que.setWhereClause(conds); if (ierr < 0) { LOGGER(ibis::gVerbose > 1) << "Warning -- jRange(" << desc_ << ") could apply " << conds << " on partition " << parts.name() << ", ierr = " << ierr; throw "jRange::ctor failed to apply conditions on parts" IBIS_FILE_LINE; } ierr = que.evaluate(); if (ierr < 0) { LOGGER(ibis::gVerbose > 1) << "Warning -- jRange(" << desc_ << ") could not evaluate " << que.getWhereClause() << " on partition " << parts.name() << ", ierr = " << ierr; throw "jRange::ctor failed to evaluate constraints on parts" IBIS_FILE_LINE; } masks_.copy(*que.getHitVector()); } else { cols.getNullMask(masks_); } LOGGER(ibis::gVerbose > 2) << "jRange(" << desc_ << ") construction complete"; } // ibis::jRange::jRange
///////////////////////////////////////////////// //Copy TEST(Queue, can_create_copy_of_queue) { D_heap_Queue q(10); ASSERT_NO_THROW(D_heap_Queue que(q)); }
TEST(Queue_on_heap, can_create_queue) { ASSERT_NO_THROW(D_heap_Queue<type> que(10)); }
TEST(Queue_on_table, cant_create_queue_with_negative_size) { ASSERT_ANY_THROW(SortTable_Queue<type> que(-10)); }
TEST(Queue_on_heap, can_create_copy_of_queue_correct) { D_heap_Queue<type> q(10); D_heap_Queue<type> que(q); EXPECT_NE(&que, &q); }
TEST(Queue_on_heap, can_create_copy_of_queue) { D_heap_Queue<type> q(10); ASSERT_NO_THROW(D_heap_Queue<type> que(q)); }
TEST(Queue_on_heap, cant_create_queue_with_negative_size) { ASSERT_ANY_THROW(D_heap_Queue<type> que(-10)); }
TEST(Queue, can_create_queue) { ASSERT_NO_THROW(D_heap_Queue que(10)); }
TEST(Queue, can_create_copy_of_queue_correct) { D_heap_Queue q(10); D_heap_Queue que(q); EXPECT_NE(&que, &q); }