首页IT科技map按什么排序(map中按值排序泛型排序_yaonb的空间_百度空间)

map按什么排序(map中按值排序泛型排序_yaonb的空间_百度空间)

时间2025-08-02 08:40:52分类IT科技浏览4850
导读:2011-12-11 19:16...

2011-12-11 19:16

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);
声明:本站所有文章               ,如无特殊说明或标注                      ,均为本站原创发布              。任何个人或组织       ,在未征得本站同意时               ,禁止复制              、盗用                      、采集        、发布本站内容到任何网站       、书籍等各类媒体平台                      。如若本站内容侵犯了原著者的合法权益                      ,可联系我们进行处理        。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
development of a widely(Development of a HTTP Caching Proxy Server | Projects) boost block(boost bind使用指南 Make Progress Everyday! 博客频道 CSDN.NET)