/************************************ * file enc : ascii * author : wuyanyi09@gmail.com ************************************/ #ifndef LIMONP_MAP_FUNCTS_H #define LIMONP_MAP_FUNCTS_H #include #include #include #include #include "typedefs.h" namespace Limonp { using namespace std; template string setToString(const set& st) { if(st.empty()) { return "{}"; } stringstream ss; ss<<'{'; typename set::const_iterator it = st.begin(); ss<<*it; it++; while(it != st.end()) { ss<<", "<<*it; it++; } ss<<'}'; return ss.str(); } template string mapToString(const map& mp) { if(mp.empty()) { return "{}"; } stringstream ss; ss<<'{'; typename map::const_iterator it = mp.begin(); ss<first<<": "<second; it++; while(it != mp.end()) { ss<<", "<first<<": "<second; it++; } ss<<'}'; return ss.str(); } template string HashMapToString(const HashMap& mp) { if(mp.empty()) { return "{}"; } stringstream ss; ss<<'{'; typename HashMap::const_iterator it = mp.begin(); ss<first<<": "<second; it++; while(it != mp.end()) { ss<<", "<first<<": "<second; it++; } ss<<'}'; return ss.str(); } template string pairToString(const pair& p) { stringstream ss; ss< void printMap(const map& mp) { for(typename map::const_iterator it = mp.begin(); it != mp.end(); it++) { cout<first<<' '<second< vT getMap(const map& mp, const kT & key, const vT & defaultVal) { typename map::const_iterator it; it = mp.find(key); if(mp.end() == it) { return defaultVal; } return it->second; } template void map2Vec(const map& mp, vector > & res) { typename map::const_iterator it = mp.begin(); for(; it != mp.end(); it++) { res.push_back(*it); } } } #endif