multimap

How to remove a specific pair from a C++ multimap?

早过忘川 提交于 2020-02-01 09:55:07
问题 #include <map> ... multimap<char,int> first; first.insert(pair<char,int>('a',10)); first.insert(pair<char,int>('b',15)); first.insert(pair<char,int>('b',20)); first.insert(pair<char,int>('c',25)); Say I now want to remove one of the pairs I have just added to the map. I have examples to remove an entire key entry, which for key 'b' would remove both 'b',15 and 'b',20. But what is the code to remove just, say, the pair 'b',20? 回答1: You can use std::multimap<char, int>::equal_range , which will

How can I store multiple elements in a Rust HashMap for the same key?

淺唱寂寞╮ 提交于 2020-01-21 12:23:26
问题 I have a HashMap<u32, Sender> . Sender is a open connection object and the key is a user id. Each user can connect from multiple devices. I need to store all possible open connections for the same user id. After this I can iterate and send messages to all open connections for same user. The above HashMap only stores each user id and connection once. I need to get one key with multiple values. How can I make the value into a list or an array, so I can see which connections exist and send to

Skip same multimap values when iterating

荒凉一梦 提交于 2020-01-13 18:05:32
问题 Is there any good way to achieve the desired output below without having to remove the same values or creating another list/vector etc? I am trying to map words found in different documents to their document names as shown in the desired output. #include <iostream> #include <fstream> #include <string> #include <map> #include <sstream> using namespace std; multimap<string,string> inverts; multimap<string,string>::iterator mit; multimap<string,string>::iterator rit; pair<multimap<string,string>

Skip same multimap values when iterating

时光怂恿深爱的人放手 提交于 2020-01-13 18:04:46
问题 Is there any good way to achieve the desired output below without having to remove the same values or creating another list/vector etc? I am trying to map words found in different documents to their document names as shown in the desired output. #include <iostream> #include <fstream> #include <string> #include <map> #include <sstream> using namespace std; multimap<string,string> inverts; multimap<string,string>::iterator mit; multimap<string,string>::iterator rit; pair<multimap<string,string>

Collect Lines using Multimap Collector

喜欢而已 提交于 2020-01-11 05:22:10
问题 Is there a way to covert the below to using collectors yet? List<String[]> lines = getLines(); Multimap<String,String> multimap = ArrayListMultimap.create(); lines.forEach(line -> multimap.put(line[0],line[1]); ); 回答1: You can use Multimaps.toMultimap collector: ListMultimap<String, String> multimap = lines.stream() .collect(Multimaps.toMultimap( l -> l[0], l -> l[1], ArrayListMultimap::create )); Or if you don't need mutability, use ImmutableListMultimap.toImmutableListMultimap collector:

Google Collections on Android

你离开我真会死。 提交于 2020-01-11 03:55:06
问题 Has anyone ever used Multimaps on Android is it possible? 回答1: Guava works as-is on Android. What problems did you have? Use the released JAR, not the Guava sources. And as always, you should be using ProGuard as part of your build process to trim the size of your final binary down. 来源: https://stackoverflow.com/questions/5168505/google-collections-on-android

multimap accumulate values

家住魔仙堡 提交于 2020-01-06 02:01:08
问题 I have a multimap defined by typedef std::pair<int, int> comp_buf_pair; //pair<comp_t, dij> typedef std::pair<int, comp_buf_pair> node_buf_pair; typedef std::multimap<int, comp_buf_pair> buf_map; //key=PE, value = pair<comp_t, dij> typedef buf_map::iterator It_buf; int summ (int x, int y) {return x+y;} int total_buf_size = 0; std::cout << "\nUpdated buffer values" << std::endl; for(It_buf it = bufsz_map.begin(); it!= bufsz_map.end(); ++it) { comp_buf_pair it1 = it->second; // max buffer size

errors with multimap (key type is std::string)

给你一囗甜甜゛ 提交于 2020-01-04 04:34:33
问题 I've been having problems with getting multimap to work. I'll just show the code and describe the problem: #include <string> ... multimap<std::string, pinDelayElement> arcList pinDelayElement pde; std:string mystring = "test" arcList[mystring] = pde; However, when I compile, the last line gives me the following error: error C2676: binary '[' : 'std::multimap<_Kty,_Ty>' does not define this operator or a conversion to a type acceptable to the predefined operator with [ _Kty=std::string, _Ty

Google Maps API vs Multimap/Bing Maps API

ぐ巨炮叔叔 提交于 2020-01-03 13:03:10
问题 I want to know if anyone who has experience of using both the Google Maps API and the Multimap API can give a good reason as to why one is better than the other - or maybe a list of pros and cons? I will be working on a complete re-development of a site which currently uses the Multimap (Classic) API and want to consider the possibility of using Google Maps API instead of Multimap (now MS Bing), but I need a compelling reason to justify this decision. The site currently provides a search

How to achieve this Map<String, List<>> structure [closed]

僤鯓⒐⒋嵵緔 提交于 2020-01-01 04:32:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have data like below: Key value ----- ------ car toyota car bmw car honda fruit apple fruit banana computer acer computer asus computer ibm ... (Each row of above data is an object with fields "key" and "value", all in one List List<DataObject> ) I would like to construct the data to a Map<String, List<String>