bool addRecursive(CuckooMap* map, uint64_t key, uint64_t value, int depth) { if(depth > MAX_LOOP) { return false; } //if its empty in the first table, add it there if(getKey1(map, key) == NONE) { set1(map, key, value); } //if its empty in the second table, add it there else if(getKey2(map, key) == NONE) { set2(map, key, value); } //if both are occupied, randomly displace one and re-add the displaced one else if((xorshf96() & 1) == 0) { uint64_t pushedKey = getKey1(map, key); uint64_t pushedValue = getValue1(map, key); set1(map, key, value); return addRecursive(map, pushedKey, pushedValue, depth + 1); } else { uint64_t pushedKey = getKey2(map, key); uint64_t pushedValue = getValue2(map, key); set2(map, key, value); return addRecursive(map, pushedKey, pushedValue, depth + 1); } return true; }
void handle(event me[2]) { if(is1(flag,0)&&is1(me[1].b,0)) { if(me[1].x>=x&&me[1].x<(x+w)&&me[1].y>=y&&me[1].y<(y+h)) set1(flag,1); else set0(flag,1); } if(is1(flag,1)) {if(me[1].key==1) { if(me[1].ch==8){if(no>0){no--;st[no]=0;}} else if(me[1].ch==13){set1(flag,2);} else if(no<num&&isalnum(me[1].ch)) {st[no]=me[1].ch; no++; st[no]=0; } } if(me[1].key==2) {if(me[1].ch==72)set1(flag,3); else if(me[1].ch==80)set1(flag,4); } setfillstyle(SOLID_FILL,ACOL); bar(x,y-2,x+w+1,y+h+2); } setfillstyle(SOLID_FILL,8); bar(x+w1,y,x+w,y+h); setcolor(color); outtextxy(x+1,y+3,str); setcolor(15); outtextxy(x+1+w1,y+3,st); }
/* * Generate the contents of a THST chunk. The data encompasses all known * threads. * * Response has: * (1b) header len * (1b) bytes per entry * (2b) thread count * Then, for each thread: * (4b) threadId * (1b) thread status * (4b) tid * (4b) utime * (4b) stime * (1b) is daemon? * * The length fields exist in anticipation of adding additional fields * without wanting to break ddms or bump the full protocol version. I don't * think it warrants full versioning. They might be extraneous and could * be removed from a future version. * * Returns a new byte[] with the data inside, or NULL on failure. The * caller must call dvmReleaseTrackedAlloc() on the array. */ ArrayObject* dvmDdmGenerateThreadStats(void) { const int kHeaderLen = 4; const int kBytesPerEntry = 18; dvmLockThreadList(NULL); Thread* thread; int threadCount = 0; for (thread = gDvm.threadList; thread != NULL; thread = thread->next) threadCount++; /* * Create a temporary buffer. We can't perform heap allocation with * the thread list lock held (could cause a GC). The output is small * enough to sit on the stack. */ int bufLen = kHeaderLen + threadCount * kBytesPerEntry; u1 tmpBuf[bufLen]; u1* buf = tmpBuf; set1(buf+0, kHeaderLen); set1(buf+1, kBytesPerEntry); set2BE(buf+2, (u2) threadCount); buf += kHeaderLen; pid_t pid = getpid(); for (thread = gDvm.threadList; thread != NULL; thread = thread->next) { unsigned long utime, stime; bool isDaemon; if (!getThreadStats(pid, thread->systemTid, &utime, &stime)) { // failed; drop in empty values utime = stime = 0; } isDaemon = dvmGetFieldBoolean(thread->threadObj, gDvm.offJavaLangThread_daemon); set4BE(buf+0, thread->threadId); set1(buf+4, thread->status); set4BE(buf+5, thread->systemTid); set4BE(buf+9, utime); set4BE(buf+13, stime); set1(buf+17, isDaemon); buf += kBytesPerEntry; } dvmUnlockThreadList(); /* * Create a byte array to hold the data. */ ArrayObject* arrayObj = dvmAllocPrimitiveArray('B', bufLen, ALLOC_DEFAULT); if (arrayObj != NULL) memcpy(arrayObj->contents, tmpBuf, bufLen); return arrayObj; }
/* * Write the header into the buffer and send the packet off to the debugger. * * Takes ownership of "pReq" (currently discards it). */ static void eventFinish(JdwpState* state, ExpandBuf* pReq) { u1* buf = expandBufGetBuffer(pReq); set4BE(buf, expandBufGetLength(pReq)); set4BE(buf+4, dvmJdwpNextRequestSerial(state)); set1(buf+8, 0); /* flags */ set1(buf+9, kJdwpEventCommandSet); set1(buf+10, kJdwpCompositeCommand); dvmJdwpSendRequest(state, pReq); expandBufFree(pReq); }
/*ARGSUSED*/ void docomplete(Char **v, struct command *t) { struct varent *vp; Char *p; Char **pp; USE(t); v++; p = *v++; if (p == 0) tw_prlist(&completions); else if (*v == 0) { vp = adrof1(strip(p), &completions); if (vp && vp->vec) tw_pr(vp->vec), xputchar('\n'); else { #ifdef TDEBUG xprintf("tw_find(%s) \n", short2str(strip(p))); #endif /* TDEBUG */ pp = tw_find(strip(p), &completions, FALSE); if (pp) tw_pr(pp), xputchar('\n'); } } else set1(strip(p), saveblk(v), &completions, VAR_READWRITE); } /* end docomplete */
int main (int argc, char** argv) { static bitfield a; bitfield b = bfi1 (a); bitfield c = bfi2 (b); bitfield d = movk (c); if (d.eight != 3) abort (); if (d.five != 7) abort (); if (d.sixteen != 7531) abort (); d = set1 (d); if (d.five != 0x1f) abort (); d = set0 (d); if (d.five != 0) abort (); return 0; }
int main() { while(1){ set1(); } return 0; }
button(int x1,int y1) {x=x1;y=y1;flag=0; h=charheight+4;w=639-x1-2; w1=textwidth(" PLAY : "); w2=textwidth(" PAUSE : "); set1(flag,1); }
Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w, QMainWindow *mw) : QToolBar(mw, "NT") { //when it is created, the toolbar has 0 buttons nr_of_buttons = 0; //set the widget widget = w; widget->attach(&getpolybut); getpolybut.deactivate(); QIconSet set0(QPixmap( (const char**)arrow_small_xpm ), QPixmap( (const char**)arrow_xpm )); QIconSet set1(QPixmap( (const char**)polygon_small_xpm ), QPixmap( (const char**)polygon_xpm )); but[0] = new QToolButton(this, "deactivate layer"); but[0]->setIconSet(set0); but[0]->setTextLabel("Deactivate Layer"); but[1] = new QToolButton(this, "polygon"); but[1]->setIconSet(set1); but[1]->setTextLabel("Input Polygon"); button_group = new QButtonGroup(0, "exclusive_group"); button_group->insert(but[0]); button_group->insert(but[1]); button_group->setExclusive(true); but[0]->setToggleButton(true); but[1]->setToggleButton(true); connect(but[1], SIGNAL(stateChanged(int)), &getpolybut, SLOT(stateChanged(int))); nr_of_buttons = 2; }
TEST(TSet, compare_two_sets_of_non_equal_sizes) { const int size1 = 4, size2 = 6; TSet set1(size1), set2(size2); EXPECT_EQ(1, set1 != set2); }
int main(int argc, char *argv[]) { /* sets to be used for testing */ char s[5] = {'1','2','3','4','\0'}; char t[4] = {'1','2','3','\0'}; char u[1] = {'\0'}; char v[4] = {'x','y','z','\0'}; /* sets to contain results */ char a[SIZE]; char b[SIZE]; char c[SIZE]; char d[SIZE]; /* SetTypes for testing */ SetType set1(s); SetType set2(t); SetType set3(u); /* test of is_empty. Should output "Set is empty" followed by "Set is not empty */ set3.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n"; set1.is_empty() ? cout << "Set is empty\n" : cout << "Set is not empty\n"; /* test of is_equal. Should output "s is equal" followed by "t is not equal" */ set1.is_equal(s) ? cout << "s is equal\n" : cout << "s is not equal\n"; set1.is_equal(t) ? cout << "t is equal\n" : cout << "t is not equal\n"; /* test of is_member. Should output "4 is a member" followed by "8 is not a member */ set1.is_member('4') ? cout << "4 is a member\n" : cout << "4 is not a member\n"; set1.is_member('8') ? cout << "8 is a member\n" : cout << "8 is not a member\n"; /* test of is_subset. Should output "t is a subset" followed by "v is not a subset */ set1.is_subset(t) ? cout << "t is a subset\n" : cout << "t is not a subset\n"; set1.is_subset(v) ? cout << "v is a subset\n" : cout << "v is not a subset\n"; /* test of setunion. Should output all elements from s and v. Implicitly tests the write function. */ set1.setunion(v, a); SetType set4(a); set4.write(); /* test of intersection. Should output all elements in both t and s. */ set1.intersection(t, b); SetType set5(b); set5.write(); /* test of difference. Should output all elements only in t or only in s */ set1.difference(t, d); SetType set7(d); set7.write(); /* return success */ return 0; }
void parser_imp::code_with_callbacks(std::function<void()> && f) { m_script_state->apply([&](lua_State * L) { set_io_state set1(L, m_io_state); set_environment set2(L, m_env); m_script_state->exec_unprotected([&]() { f(); }); }); }
/* * The caller is responsible for putting value in a safe place */ void setv(const Char *var, Char *val, int flags) { Char **vec = xmalloc(2 * sizeof(Char **)); vec[0] = val; vec[1] = 0; set1(var, vec, &shvhed, flags); }
/* * The caller is responsible for putting value in a safe place */ void set(Char *var, Char *val) { Char **vec = xreallocarray(NULL, 2, sizeof(Char **)); vec[0] = val; vec[1] = 0; set1(var, vec, &shvhed); }
GUI():t1(" Application on ",450,10,0), t2("Gravitation b/w 2 mass",450,12+charheight+8,0), e1("Mass 1 : ",450,12+3*(charheight+8),15,COL1), e2("Mass 2 : ",450,12+4*(charheight+8),15,COL2), e3(" X1 : ",450,12+5*(charheight+8),15,COL1), e4(" Y1 : ",450,12+6*(charheight+8),15,COL1), e5(" X2 : ",450,12+7*(charheight+8),15,COL2), e6(" Y2 : ",450,12+8*(charheight+8),15,COL2), b(450,15+17*(charheight+8)), rb1("Motion in Monitor's ","reference frame",450,12+10*(charheight+8)), rb2("Motion in reference","frame of C.M.",450,12+12*(charheight+8)), scrbar(450,12+15.5*(charheight+8)), t3("Press ESC to exit",450,12+19*(charheight+8),0) {set1(e1.flag,0); set1(e2.flag,0); set1(e1.flag,1); set1(rb1.flag,1); set1(scrbar.flag,0); }
TEST(TSet, can_assign_set_of_equal_size) { const int size = 4; TSet set1(size), set2(size); // set1 = {1, 3} set1.InsElem(1); set1.InsElem(3); set2 = set1; EXPECT_EQ(set1, set2); }
TEST(TSet, can_assign_set_of_greater_size) { const int size1 = 4, size2 = 6; TSet set1(size1), set2(size2); // set1 = {1, 3} set1.InsElem(1); set1.InsElem(3); set2 = set1; EXPECT_EQ(set1, set2); }
SqlInsert::operator SqlStatement() const { String s = "insert into " + table.Quoted(); if(!set1.IsEmpty()) { s << set1(); if(sel.IsValid()) s << ' ' << SqlStatement(sel).GetText(); else if(!set2.IsEmpty()) s << " values " << set2(); } return SqlStatement(s); }
TEST(TSet, compare_two_equal_sets) { const int size = 4; TSet set1(size), set2(size); // set1 = set2 = {1, 3} set1.InsElem(1); set1.InsElem(3); set2.InsElem(1); set2.InsElem(3); EXPECT_EQ(set1, set2); }
TEST(TSet, can_assign_set_of_less_size) { const int size1 = 6, size2 = 4; TSet set1(size1), set2(size2); // set1 = {1, 3, 5} set1.InsElem(1); set1.InsElem(3); set1.InsElem(5); set2 = set1; EXPECT_EQ(set1, set2); }
TEST(TSet, can_use_sum_for_three_sets) { const int size = 10; TSet set0(size), set1(size), set2(size), set3(size), expSet(size); set0.InsElem(1); set1.InsElem(3); set2.InsElem(5); set3 = set0 + set1 + set2; expSet.InsElem(1); expSet.InsElem(3); expSet.InsElem(5); EXPECT_EQ(expSet, set3); }
/* * Send up a chunk of DDM data. * * While this takes the form of a JDWP "event", it doesn't interact with * other debugger traffic, and can't suspend the VM, so we skip all of * the fun event token gymnastics. */ void dvmJdwpDdmSendChunkV(JdwpState* state, int type, const struct iovec* iov, int iovcnt) { u1 header[kJDWPHeaderLen + 8]; size_t dataLen = 0; assert(iov != NULL); assert(iovcnt > 0 && iovcnt < 10); /* * "Wrap" the contents of the iovec with a JDWP/DDMS header. We do * this by creating a new copy of the vector with space for the header. */ struct iovec wrapiov[iovcnt+1]; for (int i = 0; i < iovcnt; i++) { wrapiov[i+1].iov_base = iov[i].iov_base; wrapiov[i+1].iov_len = iov[i].iov_len; dataLen += iov[i].iov_len; } /* form the header (JDWP plus DDMS) */ set4BE(header, sizeof(header) + dataLen); set4BE(header+4, dvmJdwpNextRequestSerial(state)); set1(header+8, 0); /* flags */ set1(header+9, kJDWPDdmCmdSet); set1(header+10, kJDWPDdmCmd); set4BE(header+11, type); set4BE(header+15, dataLen); wrapiov[0].iov_base = header; wrapiov[0].iov_len = sizeof(header); /* * Make sure we're in VMWAIT in case the write blocks. */ int oldStatus = dvmDbgThreadWaiting(); dvmJdwpSendBufferedRequest(state, wrapiov, iovcnt+1); dvmDbgThreadContinuing(oldStatus); }
TEST(TSet, triple_one_string_and) { const int size = 4; TSet set1(size), set2(size), set3(size), tmp(size), expSet(size); set1.InsElem(2); set2.InsElem(2); set3.InsElem(2); expSet = set1 * set2; expSet = expSet * set3; tmp = set1*set2*set3; EXPECT_EQ(expSet, tmp); }
void handle(event me[2]) {if(is1(flag,0)) {if(is1(flag,1)) {if(me[1].x>=x+w1-2&&me[1].y>y&&me[1].x<x+w1+charheight+2&&me[1].y<y+charheight+8) {setfillstyle(SOLID_FILL,ACOL);bar(x+w1-2,y,x+w1+charheight+2,y+charheight+8); if((me[1].b&1)==1){set1(flag,3);set0(flag,1);set1(flag,2);} } } if(is1(flag,2)) {if(me[1].x>x+w/2+w2+1&&me[1].y>y&&me[1].x<x+w/2+w2+charheight+9&&me[1].y<y+charheight+8) {setfillstyle(SOLID_FILL,ACOL);bar(x+w/2+w2+1,y,x+w/2+w2+charheight+9,y+charheight+8); if((me[1].b&1)==1){set1(flag,4);set0(flag,2);set1(flag,1);} } } } if(is1(flag,1)&&is1(flag,0))setcolor(1);else setcolor(8); outtextxy(x+1,y+4," PLAY : "); setcolor(0); setfillstyle(SOLID_FILL,1); int pol[8]; pol[0]=x+w1+2;pol[1]=y+1; pol[2]=x+w1+2;pol[3]=y+charheight+7; pol[4]=x+w1+(charheight+6)/sqrt(2);pol[5]=y+(charheight+6)/2+1; pol[6]=x+w1+2;pol[7]=y+1; fillpoly(4,pol); setcolor(9); drawpoly(4,pol); if(is1(flag,2)&&is1(flag,0))setcolor(2);else setcolor(8); outtextxy(x+1+w/2,y+4," PAUSE : "); setcolor(0); setfillstyle(SOLID_FILL,2); bar(x+w/2+w2+3,y+2,x+w/2+w2+charheight+7,y+charheight+6); setcolor(11); rectangle(x+w/2+w2+3,y+2,x+w/2+w2+charheight+7,y+charheight+6); line(x+w/2+7+w2,y+5,x+w/2+7+w2,y+charheight+3); line(x+w/2+11+w2,y+5,x+w/2+11+w2,y+charheight+3); }
TEST(TSet, check_negation_operator) { const int size = 4; TSet set(size), set1(size), expSet(size); // set1 = {1, 3} set.InsElem(1); set.InsElem(3); set1 = ~set; // expSet = {0, 2} expSet.InsElem(0); expSet.InsElem(2); EXPECT_EQ(expSet, set1); }
Tools_toolbar::Tools_toolbar(CGAL::Qt_widget *w, QMainWindow *mw) : QToolBar(mw, "NT") { w->attach(&input_point); input_point.deactivate(); w->attach(&input_line); input_line.deactivate(); w->attach(&input_polygon); input_polygon.deactivate(); //set the widget widget = w; QIconSet set0(QPixmap( (const char**)arrow_small_xpm ), QPixmap( (const char**)arrow_xpm )); QIconSet set1(QPixmap( (const char**)point_small_xpm ), QPixmap( (const char**)point_xpm )); QIconSet set2(QPixmap( (const char**)line_small_xpm ), QPixmap( (const char**)line_xpm )); QIconSet set3(QPixmap( (const char**)polygon_small_xpm ), QPixmap( (const char**)polygon_xpm )); but[0] = new QToolButton(this, "Deactivate Layer"); but[0]->setIconSet(set0); but[0]->setTextLabel("Deactivate Layer"); but[1] = new QToolButton(this, "pointinput layer"); but[1]->setIconSet(set1); but[1]->setTextLabel("Input Point"); but[2] = new QToolButton(this, "lineinput layer"); but[2]->setIconSet(set2); but[2]->setTextLabel("Input Line"); but[3] = new QToolButton(this, "polygoninput layer"); but[3]->setIconSet(set3); but[3]->setTextLabel("Input Simple Polygon"); nr_of_buttons = 4; button_group = new QButtonGroup(0, "My_group"); for(int i = 0; i<nr_of_buttons; i++) { button_group->insert(but[i]); but[i]->setToggleButton(true); } button_group->setExclusive(true); connect(but[1], SIGNAL(stateChanged(int)), &input_point, SLOT(stateChanged(int))); connect(but[2], SIGNAL(stateChanged(int)), &input_line, SLOT(stateChanged(int))); connect(but[3], SIGNAL(stateChanged(int)), &input_polygon, SLOT(stateChanged(int))); }
TEST(IntervalTest, InfixOperator) { IntervalSet<int> set1(Bound<int>::closed(0), Bound<int>::closed(1)); IntervalSet<int> set2(Bound<int>::closed(2), Bound<int>::open(3)); IntervalSet<int> set3(Bound<int>::closed(0), Bound<int>::closed(2)); EXPECT_EQ(set3, set1 + set2); EXPECT_EQ(set3, set1 + (Bound<int>::closed(2), Bound<int>::open(3))); EXPECT_EQ(set3, set1 + 2); EXPECT_EQ(set1, set3 - set2); EXPECT_EQ(set2, set3 - (Bound<int>::closed(0), Bound<int>::closed(1))); EXPECT_EQ(set1, set3 - 2); }
static void *limiter_new(t_symbol *s, int argc, t_atom *argv) { t_limiter *x = (t_limiter *)pd_new(limiter_class); int i = 0; if (argc) set_bufsize(x, atom_getfloat(argv)); else { argc = 1; set_bufsize(x, 0); } if (argc > 64) argc=64; if (argc == 0) argc=1; x->number_of_inlets = argc--; while (argc--) { inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); } outlet_new(&x->x_obj, &s_signal); x->in = (t_inbuf*)getbytes(sizeof(t_inbuf) * x->number_of_inlets); while (i < x->number_of_inlets) { int n; t_sample* buf = (t_sample *)getbytes(sizeof(*buf) * x->buf_size); x->in[i].ringbuf = buf; x->in[i].buf_position = 0; for (n = 0; n < x->buf_size; n++) x->in[i].ringbuf[n] = 0.; i++; } x->val1 = (t_limctl *)getbytes(sizeof(t_limctl)); x->val2 = (t_limctl *)getbytes(sizeof(t_limctl)); x->cmp = (t_cmpctl *)getbytes(sizeof(t_cmpctl)); x->cmp->ratio = 1.; x->cmp->treshold = 1; set1(x, 100, 30, 139); set2(x, 110, 5, 14.2); x->amplification= 1; x->samples_left = x->still_left = x->mode = 0; return (x); }
void dlgSelectConnection::OnChangeServer(wxCommandEvent& ev) { if (!GetServer()) return; cbDatabase->Clear(); int sel=cbServer->GetCurrentSelection(); if (sel >= 0) { remoteServer = (pgServer*)cbServer->GetClientData(sel); if (!remoteServer->GetConnected()) { remoteServer->Connect(mainForm, remoteServer->GetStorePwd()); if (!remoteServer->GetConnected()) { wxLogError(wxT("%s"), remoteServer->GetLastError().c_str()); return; } } if (remoteServer->GetConnected()) { pgSetIterator set1(remoteServer->GetConnection(), wxT("SELECT DISTINCT datname\n") wxT(" FROM pg_database db\n") wxT(" WHERE datallowconn ORDER BY datname")); while(set1.RowsLeft()) cbDatabase->Append(set1.GetVal(wxT("datname"))); if (cbDatabase->GetCount()) cbDatabase->SetSelection(0); pgSetIterator set2(remoteServer->GetConnection(), wxT("SELECT DISTINCT usename\n") wxT("FROM pg_user db\n") wxT("ORDER BY usename")); while(set2.RowsLeft()) cbUsername->Append(set2.GetVal(wxT("usename"))); if (cbUsername->GetCount()) cbUsername->SetSelection(0); } } OnChangeDatabase(ev); }
static void _serial_init(int bord_rate, int data, int parity, int stop) { setval(GPHCON, 0xa, 4, 4 + 4 * UART_NR); setbit(GPHUP, 0x3, 2 + 2 * UART_NR); switch(data) { case 5: clrbit(ULCON, 0x3, 0); break; case 6: setval(ULCON, 0x1, 2, 0); break; case 7: setval(ULCON, 0x2, 2, 0); break; case 8: default: setbit(ULCON, 0x3, 0); } switch(parity) { case 1: setval(ULCON, 0x4, 3, 3); break; case 2: setval(ULCON, 0x5, 3, 3); break; case 0: default: clrbit(ULCON, 0x7, 3); } switch(stop) { case 2: set1(ULCON, 2); break; case 1: default: set0(ULCON, 2); } setval(UCON, 0x5, 4, 0); UBRDIV = get_pclk() / (bord_rate * 16) - 1; }