inline std::string PrettyPrint(const std::unordered_multimap<A, B, Hash, Predicate, Allocator>& maptoprint, const bool add_delimiters=false, const std::string& separator=", ") { std::ostringstream strm; if (maptoprint.size() > 0) { if (add_delimiters) { strm << "{"; typename std::unordered_multimap<A, B, Hash, Predicate, Allocator>::const_iterator itr; for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr) { std::pair<A, B> cur_pair(itr->first, itr->second); if (itr != maptoprint.begin()) { strm << separator << PrettyPrint(cur_pair, add_delimiters, separator); } else { strm << PrettyPrint(cur_pair, add_delimiters, separator); } } strm << "}"; } else { typename std::unordered_multimap<A, B, Hash, Predicate, Allocator>::const_iterator itr; for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr) { std::pair<A, B> cur_pair(itr->first, itr->second); if (itr != maptoprint.begin()) { strm << separator << PrettyPrint(cur_pair, add_delimiters, separator); } else { strm << PrettyPrint(cur_pair, add_delimiters, separator); } } } } return strm.str(); }
void f_unordered_multimap() { std::unordered_multimap<int, int> C; std::unordered_multimap<int, int>::iterator UMMapI1 = C.begin(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators // CHECK-FIXES: auto UMMapI1 = C.begin(); const std::unordered_multimap<int, int> D; std::unordered_multimap<int, int>::const_iterator UMMapI2 = D.begin(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators // CHECK-FIXES: auto UMMapI2 = D.begin(); }
//calculate the given dynamical-network's maxminum B and its corresponding w std::pair<int,double> calmaxBW(std::unordered_multimap<int,std::pair<int,int>> &SN) { int maxB = 0,temp,attractor = 0; double Wn; for(auto it = SN.begin(); it != SN.end(); it++){ if(it->first == it->second.first){ temp = calBRec(SN,it->second.first); if(temp > maxB){ maxB = temp; attractor = it->first;//main attractor } } } Wn = calWRec(SN,attractor,1,0); return std::make_pair(maxB,Wn/maxB); }
//find the maximum B:basin for a given directed network std::pair<int,double> findMaxBW(std::unordered_multimap<int,std::pair<int,int>> &SN,double *TF) { int maxB = 0,temp,attractor = 0; double Wn; for(auto it = SN.begin(); it != SN.end(); it++){ /**!!!!!!!!!!!your must change attractor!!!!!!!!**/ if(it->first == it->second.first && it->first == 76){ temp = findMaxBRec(SN,it->second.first,TF); if(temp > maxB){ maxB = temp; attractor = it->first;//main attractor } } } Wn = calWRec(SN,attractor,1,0); return std::make_pair(maxB,Wn/maxB); }
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const { o.type = msgpack::type::MAP; if(v.empty()) { o.via.map.ptr = nullptr; o.via.map.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); msgpack::object_kv* const pend = p + size; o.via.map.ptr = p; o.via.map.size = size; typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()); do { p->key = msgpack::object(it->first, o.zone); p->val = msgpack::object(it->second, o.zone); ++p; ++it; } while(p < pend); } }