vector<pair<int, float> > Clusters::cluster_distances(int user) { map<int, float> rhash; for(int i = 0; i < nclusters; i++) { float m = dist(&(*mods)[user], ¢roids[i]); if(m == 0) continue; rhash[i] = m; } if(rhash.size() == 0) for(int i = 0; i < nclusters; i++) rhash[i] = centroids[i].size(); return sort_hash(rhash); }
//////////////////////////////////////////////////////////////////////////////////////////////// // // @tsv - Utility to convert export list to different required format // // USAGE: makeexport module_exportlist.c module_exportlist.h exportlist.txt module_hashlist.h // /////////////////////////////////////////////////////////////////////////////////////////////// int main( int argc, char **argv ) { if ( argc < 5 ) { printf("#error Not enough arguments for export list maker.\n"); exit(-1); } char* file1 = load_from_file( argv[1]); FILE* out_h = fopen(argv[2],"wb"); FILE* out_txt = fopen(argv[3],"wb"); FILE* out_hash = fopen(argv[4],"wb"); if (!out_h) { printf("#error Error creation exportlist.h.\n"); exit(-1); } if (!out_txt) { printf("#error Error creation exportlist.txt.\n"); exit(-1); } fprintf(out_h,"//Auto generated file. Do not edit the contents of this file.\n"); fprintf(out_h,"//Update the core/module_exportlist.c\n\n"); fprintf(out_h,"#ifndef MODULE_EXPORTLIST_H\n"); fprintf(out_h,"#define MODULE_EXPORTLIST_H\n\n"); // Separate CHDK build num char* build = BUILD_NUMBER; char* e; int build_num=0; int mult=10000; for ( ; *build; build++) { if ( *build<'0' || *build>'9') continue; build_num += mult*strtol(build, &e, 0/*autodetect base oct-dec-hex*/); if ( mult==1 ) break; build=e; mult/=100; } if ( *build ) fprintf(out_h,"#define CHDK_BUILD_NUM %d\n\n",build_num); num_lines=0; char* cur, *cursym; cur = file1; const char* exp_def_tag="/* EXPORTED_DEFINES_"; int flag_section_defines = 0; fprintf(out_h,"#ifndef THIS_IS_CHDK_CORE\n"); for(; *cur && *cur!='{'; cur++) { if ( !strncmp(cur,exp_def_tag,strlen(exp_def_tag)) ) { cur+=strlen(exp_def_tag); if (*cur=='B' ) { fprintf(out_h,"\n//Section: exported defines\n"); flag_section_defines=1; } else if (*cur=='E' ) { flag_section_defines=0;} for(; *cur && *cur!=10; cur++); } if (flag_section_defines) { cursym=cur; for(; *cur && *cur!=10 && *cur!='='; cur++); if ( *cur=='=' ) { *cur=0; cur++; cut_export_token(cursym); char *symbol = find_last_token(cursym); fprintf(out_h,"#undef %s\n",symbol); fprintf(out_h,"extern %s;\n",cursym); for(; *cur && *cur!=10; cur++); //goto eol } } } fprintf(out_h,"#endif\n"); fprintf(out_h,"\n\n"); fprintf(out_h,"\n//Section: ids of exported symbols\n"); for(; *cur && *cur!=10; cur++); //get eol // Main cycle for(;*cur; ) { for(; *cur==9 || *cur==' '; cur++); if (*cur=='(') { for(cur++; *cur && *cur!=')'; cur++); for(; *cur==9 || *cur==' ' || *cur==')'; cur++); } //printf("%x [%c]\n",cur-file1,*cur); if ( *cur=='}') {break;} int is_address = 0; if (*cur=='&') { is_address = 1; for(cur++; *cur==9 || *cur==' '; cur++); } cursym=cur; for(; (*cur>='A' && *cur<='Z') || (*cur>='a' && *cur<='z') || (*cur>='0' && *cur<='9') || *cur=='_'; cur++); if (cursym!=cur) { char symbol[256], full_symbol[257]; int size=cur-cursym; if ( size>255) {size=255;} memcpy(symbol,cursym,size); symbol[size]=0; full_symbol[0] = 0; if (is_address) strcpy(full_symbol,"&"); strcat(full_symbol,symbol); cut_export_token(symbol); unsigned int hash_val = hash((unsigned char*)symbol); add_hash(hash_val,full_symbol); fprintf(out_txt,"%08x %s\n",hash_val,symbol); for(; size>=0; size--) { if ( symbol[size]>='a' && symbol[size]<='z') symbol[size]-=0x20; } fprintf(out_h,"#define MODULESYM_%-32s 0x%08x\n",symbol,hash_val); num_lines++; } for(; *cur && *cur!=10; cur++); for(; *cur==10; cur++); } sort_hash(); fprintf(out_hash,"// This is an automatically generated file. DO NOT EDIT!\n"); int n; for (n=0; n<hash_idx; n++) { fprintf(out_hash,"{ 0x%08x, %s },\n",hash_vals[n].hash,hash_vals[n].symbol); } if (num_lines>=1) fprintf(out_h,"\n#define EXPORTLIST_LAST_IDX %d\n\n",num_lines); else { fprintf(out_h,"#error Malformed export list. Only %d valid records\n\n",num_lines); exit(-2); } fprintf(out_h,"#endif\n"); fclose(out_h); fclose(out_txt); fclose(out_hash); return 0; }
git_wc_status2_t * GitStatus::GetFirstFileStatus(const CTGitPath& path, CTGitPath& retPath, bool update, git_depth_t depth, bool bNoIgnore /* = true */, bool bNoExternals /* = false */) { static git_wc_status2 st; /* m_fileCache.Reset(); m_fileCache.Init( CStringA( path.GetWinPathString().GetString() ) ); MessageBox(NULL, path.GetWinPathString(), _T("GetFirstFile"), MB_OK); m_fileCache.m_pFileIter = m_fileCache.m_pFiles; st.text_status = git_wc_status_none; if (m_fileCache.m_pFileIter) { switch(m_fileCache.m_pFileIter->nStatus) { case WGFS_Normal: st.text_status = git_wc_status_normal; break; case WGFS_Modified: st.text_status = git_wc_status_modified; break; case WGFS_Deleted: st.text_status = git_wc_status_deleted; break; } //retPath.SetFromGit((const char*)item->key); m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext; } return &st; */ #if 0 const sort_item* item; git_error_clear(m_err); m_statushash = apr_hash_make(m_pool); m_externalhash = apr_hash_make(m_pool); headrev = Git_INVALID_REVNUM; git_opt_revision_t rev; rev.kind = git_opt_revision_unspecified; struct hashbaton_t hashbaton; hashbaton.hash = m_statushash; hashbaton.exthash = m_externalhash; hashbaton.pThis = this; m_statushashindex = 0; m_err = git_client_status4 (&headrev, path.GetGitApiPath(m_pool), &rev, getstatushash, &hashbaton, depth, TRUE, //getall update, //update bNoIgnore, //noignore bNoExternals, //noexternals NULL, ctx, m_pool); // Error present if function is not under version control if ((m_err != NULL) || (apr_hash_count(m_statushash) == 0)) { return NULL; } // Convert the unordered hash to an ordered, sorted array m_statusarray = sort_hash (m_statushash, sort_compare_items_as_paths, m_pool); // only the first entry is needed (no recurse) m_statushashindex = 0; item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item); retPath.SetFromGit((const char*)item->key); return (git_wc_status2_t *) item->value; #endif return 0; }
// Generates the list of users who are similar to the user u. // if the user has not yet been binned by the recommender, vector<pair<int, float> > &Recommender::similar_users(int user, bool tryAgain, bool redo) { // if(!sim_users.has_key(user)) { if(redo || tryAgain || sim_users.find(user) == sim_users.end()) { map<int, float> rhash; vector<pair<int, float> > rval; int counter= 0; if (tryAgain || !cl.has_user(user)) cl(user, tryAgain); if (verbose) cout << "\x1b[34m" << user << ": \x1b[0m" ; vector<pair<int, float> > i = cl.cluster_distances(user); if(i.size() == 0) { if (verbose) cout << " --> \x1b[33m\x1b[1mUnclusterable user!!! " << mods[user].size() << " mods available \x1b[0m" << endl; return blank; } float closest_cluster_dist = i[0].second; if (verbose) cout << "\x1b[35mMost similar cluster: " ; int pos_count = 0; int neg_count = 0; int n = 0; while(n < i.size() && i[n++].second == closest_cluster_dist) { if (verbose) cout << i[n-1].first << ", "; int j = i[n].first; if(j >= 0 && j < cl.size()) { vector<int>::iterator user2; for(user2 = cl.begin(j); user2 != cl.end(j); user2++) { if(user != (*user2) && !mods[user].empty()) { User *i1 = &mods[user]; float dist = 0, denom1 = 0, denom2 = 0; for(User::iterator art = i1->begin(); art != i1->end(); art++) { counter ++; float part1 = (*art).second; float part2; part2 = user_preference((*user2), (*art).first); dist += part1 * part2; denom1 += part1 * part1; denom2 += part2 * part2; } if(dist > 0) pos_count++; if(dist < 0) neg_count++; if(denom1* denom2 != 0 && dist != 0) rhash[(*user2)] = dist/sqrt(denom1*denom2); } } } } if (verbose) cout << " Q = " << closest_cluster_dist << " -> " << rhash.size() << " users" << "( " << pos_count << " similar, " << neg_count << " different)" << "\x1b[0m" << endl; if(!rhash.empty()) { rval = sort_hash(rhash); } else { cout << " --> \x1b[33m\x1b[1mUnclusterable user!!! Resorting to alternative method\x1b[0m" << endl; int j = i[0].first; vector<int>::iterator user2; for(user2 = cl.begin(j); user2 != cl.end(j); user2++) { rhash[(*user2)] = 0; } rval = sort_hash(rhash); } cout << "\t" << rval.size() << " results " << endl; sim_users[user] = rval; } return sim_users[user]; }