zoukankan      html  css  js  c++  java
  • map中按值排序泛型排序_yaonb的空间_百度空间

    map中按值排序---泛型排序_yaonb的空间_百度空间

    map中按值排序---泛型排序
    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);
  • 相关阅读:
    word 操作技巧
    有朝一日
    菜狗日记2021.7.10
    记一次JSON.toJSONString()踩坑
    菜狗日记2020.11.13
    菜狗日记2020.11.6
    菜狗日记2020.11.03
    菜狗日记2020.10.29
    菜狗日记2020.10.17
    菜狗日记2020.10.11
  • 原文地址:https://www.cnblogs.com/lexus/p/2599938.html
Copyright © 2011-2022 走看看