/// /// \return The set of leaf nodes. If this node is a leaf node, it is /// returned in the collection. /// std::set<pointer_type> find_leafs() { return find_all([](pointer_type node) -> bool { return node->is_leaf(); }); }
int loop_dictionary(char *path, char *output, char **field, char **scores, int dim, List *moves) { /* the stream rappresenting the dictionary file indicated in path [read only]*/ FILE *file = fopen(path, "r"); /* the current word (suppose max length 100 chars)*/ char cword[100]; /* indicates if the current word is present in the matrix */ int present; /* to clean the previus version of the output file [write, NOT append]*/ FILE *file_out = fopen(output, "w"); fclose(file_out); /* if the stream is valid (not null)*/ if (file) /* while the file is not finished */ while (fscanf(file, "%s", cword) && !feof(file)) { /* upcase current word */ upcase(cword); /* check if it's present */ present = find_all(field, scores, cword, dim, &(*moves)); if (present) { /* since the current word is present in the matrix, save it in the output file */ save_on_file(output, *moves, scores); } /* clean the moves list*/ free_list(*moves); *moves = NULL; } /* close the output file to prevent errors */ fclose(file); return STATUS_SUCCESS; }
int run(Object& m, const std::size_t count, const std::size_t tries) { m.add("construction"); m.add("search"); std::printf("%s\n", m.name.c_str()); auto result = 0; Collection list; { std::printf("* construction... "); std::fflush(stdout); auto c = scoped_timer<Timer>(m["construction"]); generate(count, list); std::printf("%.3fs\n", c.in_seconds()); } std::printf("* search... ["); std::fflush(stdout); for (std::size_t i=0; i < tries; i++) { auto c = scoped_timer<Timer>(m["search"]); result += find_all(count, list); std::putchar('.'); std::fflush(stdout); } std::printf("] min=%.3f, max=%.3f, avg=%.3fs\n", m["search"].min(), m["search"].max(), m["search"].avg()); return result; }
/// /// \return The set of leaf nodes. If this node is a leaf node, it is /// returned in the collection. /// std::set<const_pointer_type> find_leafs() const { return find_all([](const_pointer_type node) -> bool { return node->is_leaf(); }); }
/// /// \return The collection of descendents of this node. /// inline std::set<pointer_type> find_descendents() { return find_all([this](pointer_type node) -> bool { return node != this; }); }
int main() { int target = 20; vector<vector<IntPair>> vset; vset.resize(target+1); vset[1].push_back(IntPair(1,1)); //for each level for(int n=2; n<=target; ++n) { vmap.clear(); vmap.resize(msize*msize, false); vector<IntPair>& cset=vset[n-1]; printf("%d %zu\n", n-1, cset.size()); for(int n1 = 1; n1 <= n/2; ++n1) find_all(vset[n], vset[n1], vset[n-n1]); } vmap.clear(); vmap.resize(msize*msize, false); int cnt = 0; for( int i = 3; i<=target; ++i) { for(auto iter = vset[i].begin(); iter != vset[i].end(); ++iter) { if(!vmap[iter->first*msize+iter->second]) { vmap[iter->first*msize+iter->second]= true; ++cnt; } } } printf("%d %d\n", target, cnt*2-1); }
std::vector <std::pair <size_t, size_t> > StringMatch::match (const std::wstring &haystack) const { #ifdef TIARY_USE_PCRE if (PcRe *rex = regex.get ()) { return rex->match (haystack); } else #endif { return find_all (strlower (haystack), strlower (pattern)); } }
bool SearchSupport::search( const Glib::ustring &pattern, ViTextIter &start, Direction direction ) { if (m_buffer == NULL) { g_print("ERROR: Buffer not set.\n"); return false; } if (!find_all(pattern)) { g_print("No matches found.\n"); return false; } std::list< MatchInfo* >::iterator end; if (direction == Forward) { std::list< MatchInfo* >::iterator it; for ( it = m_matches.begin(); it != m_matches.end(); it++) { if ((*it)->start_pos > start.get_offset()) { g_print("Matched! current position = %i\n", start.get_offset()); start.set_offset((*it)->start_pos); return true; } } } else { std::list< MatchInfo* >::reverse_iterator it; for ( it = m_matches.rbegin(); it != m_matches.rend(); it++) { if ((*it)->start_pos < start.get_offset()) { g_print("Matched! current position = %i\n", start.get_offset()); start.set_offset((*it)->start_pos); return true; } } } g_print("Match not found. current cursor position = %i\n", start.get_offset()); return false; }
void ShortcutListModel::add_new_item(const ApplicationShortcuts &shortcuts, const QString &command, const QKeySequence &sequence){ if (this->sequence_already_exists(command)) return; auto info = shortcuts.get_shortcut_info(command); if (!info) return; auto it = find_all(this->items.begin(), this->items.end(), [=](const ShortcutTriple &a){ return info->display_name < a.display_name; }); auto position = it - this->items.begin(); ShortcutTriple triple; triple.command = command; triple.display_name = info->display_name; triple.sequence = sequence; this->beginInsertRows(QModelIndex(), position, position); this->items.insert(it, triple); this->endInsertRows(); emit item_inserted_at(position); }
bool patch(std::fstream &file, char* buffer, size_t size) { std::vector<size_t> advapi; find_all(buffer, "ADVAPI32", size, 8, advapi); std::vector<int> functionlist; bool fullcheck = false; bool supported = true; if (!advapi.empty()) { if (fullcheck) for (int i = 0; i < 806; i++) { size_t func_len = strlen(Advapi_Function[i]); if (find_single(buffer, Advapi_Function[i], size, func_len)) { functionlist.push_back(i); supported = supported && Advapi_Support[i]; } }; if (supported) { for (size_t pos : advapi) { file.seekg(pos, std::ios::beg); file.write("REGEMU32", 8); } } wprintf(L"ADVAPI32 found (%d) and patched. ", advapi.size()); } else { wprintf(L"ADVAPI32 not found. "); } return !advapi.empty(); }
bool unpatch(std::fstream &file, char* buffer, size_t size) { std::vector<size_t> regemu; find_all(buffer, "REGEMU32", size, 8, regemu); if (!regemu.empty()) { for (size_t pos : regemu) { file.seekg(pos, std::ios::beg); file.write("ADVAPI32", 8); } wprintf(L"REGEMU32 found (%d) and unpatched. ", regemu.size()); } else { wprintf(L"REGEMU32 not found. "); } return !regemu.empty(); }
int p_seven() { char buf1[8],log[80]; char *kind[9]= {"¯QÀs","³æF","¨ßF","¤T±ø","¶¶¤l","¦Pªá","¸¬Äª", "ÅK¤ä","¬h¤B" }; char *poker[52]= {"¢±","¢±","¢±","¢±","¢²","¢²","¢²","¢²", "¢³","¢³","¢³","¢³","¢´","¢´","¢´","¢´","¢µ","¢µ","¢µ","¢µ", "¢¶","¢¶","¢¶","¢¶","¢·","¢·","¢·","¢·","¢¸","¢¸","¢¸","¢¸", "10","10","10","10","¢Ø","¢Ø","¢Ø","¢Ø","¢ß","¢ß","¢ß","¢ß", "¢Ù","¢Ù","¢Ù","¢Ù","¢Ï","¢Ï","¢Ï","¢Ï" }; int cardlist[52]= {0}; int mark[2]= {7,7}, set[6],key,tax=0; /* tax ¬°ª±®aĹ®É©âªºµ| */ int i,j,k,x,m,ch,z=1; int win,color,color2,bet; int host_card[7]= {0}, guest_card[7]= {0}; time_t now = time(0); time(&now); while(-1) { clear(); setutmpmode(SEVENCARD); showtitle("½ä«°¤C±i", BoardName); show_money(bet=0); do { getdata(21, 0,"n¤Uª`¦h¤Ö©O(¤W250000)? «ö Enter Â÷¶}>", buf1, 7, 1, 0); bet=atoi(buf1); if(bet<0) bet=0; } while(bet>250000); if(!bet) return 0; if(bet>cuser.silvermoney) { pressanykey("§Aªº²{ª÷¤£°÷³á.. :)"); return 0; } demoney(bet); show_money(bet); move(21,0); prints("(«ö ¡ô¡õ¡ö¡÷ ©Î ijkl ¿ïµP, ¿ï¦n«ö enter ÅuµP)"); for(i=0; i<52; i++) cardlist[i]=0; mark[0]=mark[1]=7; z=1; for(i=1; i<=52; i++) { m=0; do { j=(time(0)+cuser.silvermoney+random())%52; if (cardlist[j]==0) { cardlist[j]=i; m=1; } } while(m==0); }; for(i=0; i<52; i++)cardlist[i]--; /* ¬~µP */ j=0; for(i=0; i<7; i++) { host_card[i]=cardlist[j]; j++; guest_card[i]=cardlist[j]; j++; } /* µo«e¤Q¥|±iµP */ for(i=0; i<7; i++) { for(j=0; j<(6-i); j++) { if(guest_card[j]>guest_card[j+1]) { x=guest_card[j]; guest_card[j]=guest_card[j+1]; guest_card[j+1]=x; } if(host_card[j]>host_card[j+1]) { x=host_card[j]; host_card[j]=host_card[j+1]; host_card[j+1]=x; } } } /* ±Æ§Ç */ move(1,0); prints("[33;1m¥»¹CÀ¸¥Ñ¯îÂÕ¤Û¹Ò(weird.twbbs.org)¯¸ªø weiren ³]p´£¨Ñ! ¯S¦¹·PÁÂ!!\n"); prints("e-mail: [email protected][m"); move(3,0); prints("¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢~¢w¢w¢w¢¡"); move(4,0); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(5,0); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(6,0); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(7,0); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(8,0); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(9,0); prints("¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢¢¢w¢w¢w¢£"); for(i=0; i<7; i++) { print_Scard(guest_card[i],11,0+4*i); /* ¦L¥X«e¤C±iµP */ } j=2; k=0; x=0; move(15,2); do { ch=igetkey(); switch (ch) { case KEY_RIGHT: case 'l': j+=4; if(j>26)j=26; break; case KEY_LEFT: case 'j': j-=4; if(j<2)j=2; break; case KEY_UP: case 'i': k=(j-2)/4; if(x<2&&mark[0]!=k&&mark[1]!=k) { if(mark[0]==7)mark[0]=k; else mark[1]=k; x++; cursor_show(15,j); } break; case KEY_DOWN: case 'k': k=(j-2)/4; if(mark[0]==k) { mark[0]=7; x--; } if(mark[1]==k) { mark[1]=7; x--; } cursor_clear(15,j); break; case 13: /* ¿ï¥X¨â±i«á«ö enter */ if(x==2)z=0; break; prints("¥»¹CÀ¸¥Ñ¯îÂÕ¤Û¹Ò(weird.twbbs.org)¯¸ªø weiren ³]p\n"); prints("e-mail: [email protected]"); } move(15,j); } while(z==1); if(mark[0]>mark[1]) { i=mark[0]; mark[0]=mark[1]; mark[1]=i; } for(i=1; i<18; i++) { move(i,0); clrtoeol(); } print_Scard(guest_card[mark[0]],11,0); print_Scard(guest_card[mark[1]],11,4); j=0; for(i=0; i<7; i++) { if(i!=mark[0]&&i!=mark[1]) { print_Scard(guest_card[i],11,16+j*4); set[j]=guest_card[i]; j++; } } /* ¦L¥Xª±®a¤À¦n¨â°ô«áªºµP */ set[5]=5; if(diedragon(set,guest_card[mark[0]],guest_card[mark[1]])==1) { ; pressanykey("ËÀs!"); continue; } if(guest_card[mark[0]]/4==guest_card[mark[1]]/4)x=1; key=find_host(host_card); print_hostcard(host_card,key,log); i=bigsmall(host_card,guest_card,key,mark); switch(i) { case 0: win=2; color=41; color2=41; break; /* ª±®a duA duB ¬ÒĹ */ case 1: win=1; color=41; color2=47; break; /* duA Ĺ duB ¿é */ case 2: win=1; color=47; color2=41; break; /* duA ¿é duB Ĺ */ case 3: win=0; color=47; color2=47; break; /* ¨â½ä¬Ò¿é */ } game_log(SEVENCARD,"§ÚªºµP[46;1m%s%s%s[m..¹q¸£[45;1m%s[m..%s..%d[m",poker[guest_card[mark[0]]], x==1?"F":poker[guest_card[mark[1]]],kind[find_all(set)],log, win?(win==1?"[33;1m¥¤â":"[32;1mŤF"):"[31;1m¿é¤F",bet); move(15,4); prints("[1;%d;%dm %s%s [m ¢x ¢x [1;%d;%dm %s [m" ,color, color==41?33:30 ,poker[guest_card[mark[0]]],x==1?"F":poker[guest_card[mark[1]]] ,color2, color2==41?33:30 ,kind[find_all(set)]); i=bet*2-bet/100*tax; switch(win) { case 2: pressanykey("[1;33m§AŤF %d !!.. :D[44m",i-bet); inmoney(i); break; case 1: pressanykey("[1;36m¥¤â!!..[44m"); inmoney(bet); break; case 0: pressanykey("[1;31m§A¿é¤F³á.. :))[44m" ); break; } } }
tripoint overmapbuffer::find_random( const tripoint &origin, const std::string &type, int dist, bool must_be_seen ) { return random_entry( find_all( origin, type, dist, must_be_seen ), overmap::invalid_tripoint ); }
void Bayes::sample_muOmega() { double tau = 10.0; int d0 = p + 2; // matrix_t S0(p, p); ublas::matrix<double> S0(p, p); S0 = d0 * ublas::identity_matrix<double>(p, p)/4.0; std::vector<int> idx; ublas::indirect_array<> irow(p); // projection - want every row for (size_t i=0; i<irow.size(); ++i) irow(i) = i; // size_t rank; ublas::matrix<double> S(p, p); // matrix_t SS(p, p); ublas::matrix<double> SS(p, p); ublas::matrix<double> Omega_inv(p, p); // identity matrix for inverting cholesky factorization ublas::matrix<double> I(p, p); I.assign(ublas::identity_matrix<double> (p, p)); ublas::symmetric_adaptor<ublas::matrix<double>, ublas::upper> SH(I); // triangular matrix for cholesky_decompose ublas::triangular_matrix<double, ublas::lower, ublas::row_major> L(p, p); int df; for (int j=0; j<k; ++j) { idx = find_all(z, j); int n_idx = idx.size(); ublas::matrix<double> xx(p, n_idx); ublas::matrix<double> e(p, n_idx); // ublas::matrix<double> m(p, 1); ublas::vector<double> m(p); ublas::indirect_array<> icol(n_idx); for (size_t i=0; i<idx.size(); ++i) icol(i) = idx[i]; if (n_idx > 0) { double a = tau/(1.0 + n_idx*tau); //! REFACTOR - should be able to do matrix_sum directly on projection rather than make a copy? xx.assign(project(x, irow, icol)); m.assign(ublas::matrix_sum(xx, 1)/n_idx); // e.assign(xx - outer_prod(column(m, 0), ublas::scalar_vector<double>(n_idx, 1))); e.assign(xx - outer_prod(m, ublas::scalar_vector<double>(n_idx, 1))); S.assign(prod(e, trans(e)) + outer_prod(m, m) * n_idx * a/tau); // SS = trans(S) + S0; SS = S + S0; df = d0 + n_idx; // Omega(j).assign(wishart_rnd(df, SS)); Omega(j).assign(wishart_InvA_rnd(df, SS)); SH.assign(Omega(j)); cholesky_decompose(SH, L); Omega_inv.assign(solve(SH, I, ublas::upper_tag())); mu(j).assign(a*n_idx*m + sqrt(a)*prod(Omega_inv, Rmath::rnorm(0, 1, p))); } else { // Omega(j).assign(wishart_rnd(d0, S0)); Omega(j).assign(wishart_InvA_rnd(d0, S0)); SH.assign(Omega(j)); cholesky_decompose(SH, L); Omega_inv.assign(solve(SH, I, ublas::upper_tag())); mu(j).assign(sqrt(tau) * prod(Omega_inv, Rmath::rnorm(0, 1, p))); } } }