template <typename T> inline int cmp(pair<T,int>& v1,pair<T,int>& v2) { return v1.second > v2.second; } template <typename T> inline void SortMapByValue(map<T,int>& mapImgKeyWordsVSM, vector<pair<T,int>>& imgVSMVec) { for (map<T,int>::iterator curr = mapImgKeyWordsVSM.begin(); curr != mapImgKeyWordsVSM.end(); curr++) { imgVSMVec.push_back(std::make_pair(curr->first, curr->second)); } std::sort(imgVSMVec.begin(), imgVSMVec.end(), cmp<T>); } //分词 #include <boost\regex.hpp> #include <boost\algorithm\string.hpp> void GetVSMVectorMap(const string&strVSMTxt ,map<string,int>&keyFreMap) { keyFreMap.clear(); boost::regex expression(","); boost::sregex_token_iterator it(strVSMTxt.begin(),strVSMTxt.end(),expression,-1); boost::sregex_token_iterator itEnd; while (it!=itEnd) { string strKeyFreTxt = *it; boost::trim(strKeyFreTxt); if (!strKeyFreTxt.empty()) { int nKeyWordEPos = strKeyFreTxt.find_first_of(':'); assert(nKeyWordEPos>0); string strKeyWord = strKeyFreTxt.substr(0,nKeyWordEPos); string strFre = strKeyFreTxt.substr(nKeyWordEPos+1); int iFre = atol(strFre.c_str()); keyFreMap.insert(make_pair(strKeyWord,iFre)); } it++; } return; }
map<pair<string,string>,int>::iterator itSysVSM = mapImgSysVSM.find(it->first);
|
map中按值排序---泛型排序
2011-12-11 19:16
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)