Questions tagged [multimap]

A container similar to a map but allowing duplicate keys

Use this tag for questions about associative arrays with non-unique keys, such as the std::multimap container in the C++ standard library, or scala.collection.mutable.MultiMap in Scala.

See the Wikipedia article for more information.

773 questions
4
votes
1 answer

How to count number of duplicate pairs in multimap

how can I count the number of duplicate pairs (with same key and value) in a multimap of pairs of integers? For example, my multimap contains the pairs {(6,2), (6,2), (6,3) and (6,4)} so the duplicate count is 1 as I have 1 duplicate pair in my…
Chew Kah Meng
  • 227
  • 1
  • 10
4
votes
3 answers

How to provide custom comparator for `std::multiset` without overloading `operator()`, `std::less`, `std::greater`?

I want a custom comparator for the following code. However, I am not allowed to overload operator(), std::less, std::greater. I tried to achieve this using lambda but gcc won't allow me to use auto as a non-static member. Any other way to make…
4
votes
2 answers

How to convert List to Map> instead of Map>?

Considering Person class has three fields name(String), age(int), salary(double). I want to create a map with name as key and value as salary (instead of Person object itself), if key is not unique then use linkedList to hold the values of all…
Nipun
  • 73
  • 1
  • 9
4
votes
3 answers

Zip two lists into an immutable multimap in Java 8 with Guava?

The for loop looks like ImmutableListMultiMap.Builder builder = ImmutableListMultiMap.newBuilder(); for (int i = 0; i < Math.min(keys.length(), values.length()); i++) { builder.put(keys.at(i), values.at(i)); } A…
djechlin
  • 59,258
  • 35
  • 162
  • 290
4
votes
2 answers

Hashtable same Key with different value....?

Is it possible with java that a hashtable can map the same keys to different values? .. How can I retrieve both value from hashtable...
Ravi Parmar
  • 1,392
  • 5
  • 24
  • 46
4
votes
1 answer

Multimap.inverse() to a (non-multi) Map (values in original map known to be unique)

Is there something in Guava that allows me to get the inverse of a Multimap as a (non-multi-) Map? Consider the following: static final ImmutableMap precedences = new ImmutableSetMultimap.Builder() .put(0,…
S1lentSt0rm
  • 1,989
  • 2
  • 17
  • 28
4
votes
1 answer

Can I Copy Into a multimap

Given an istream_iterator and multimap output. I want to copy all the values into output's 'a' key. How's the best way to handle that? I had tried to use: transform( istream_iterator(input), istream_iterator(), …
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
4
votes
3 answers

Is there IdentitySetMultimap in guava or somewhere else?

Java provides IdentityHashMap which is perfect when you want to compare objects by == instead of equals method. Guava provides nice wrapper for Map which is SetMultimap. However there are no implementation of it which uses identity…
kokosing
  • 5,251
  • 5
  • 37
  • 50
4
votes
4 answers

float value used as a key in multimap

If compare between float, I think cannot just use equal ==, need to check if abs(a-b) < epsilon. So when float type value is used as a key, can we use equal_range function? such as: std::multimap ds; ds.insert(make_pair(2.0,…
yewei
  • 241
  • 2
  • 9
4
votes
1 answer

Multimap containing pairs?

Is it possible for a multimap to contain within it pairs? IE, rather then being defined as multimap for instance, it would be defined as multimap? How would this multimap then be sorted? Also, how would one access the…
BSchlinker
  • 3,401
  • 11
  • 51
  • 82
4
votes
1 answer

Emplace a pointer to a multimap of shared_ptr's doesn't work

Vector works properly Header std::vector> subnodes_m; Definition void CompositeSceneNode::AddChild(SceneNode* subnode_p) { subnodes_m.emplace_back(subnode_p); } Multimap doesn't Header std::multimap
user2032932
  • 197
  • 2
  • 11
4
votes
3 answers

Random element from elements with equivalent keys of std::unordered_multimap

How do I pick a random element from a group of elements with equivalent keys of a std::unordered_multimap? What would be the idiomatic way to do this? I know I can get the range of elements for a given key with mmap.equal_range(key). Is there a way…
fuji
  • 1,173
  • 1
  • 10
  • 27
4
votes
4 answers

Java Multimap with Trove

I have a pretty large google Multimap and was looking into ways to reduce the memory usage. In all of the examples I can find people are doing something like: Multimaps.newSetMultimap( TDecorators.wrap(new…
chrstahl89
  • 580
  • 10
  • 21
4
votes
5 answers

Time complexity issues with multimap

I created a program that finds the median of a list of numbers. The list of numbers is dynamic in that numbers can be removed and inserted (duplicate numbers can be entered) and during this time, the new median is re-evaluated and printed out. I…
user1066524
  • 373
  • 2
  • 11
  • 24
4
votes
2 answers

how to loop multimap only to get first key-value pairs for every key?

For example if I have such mmap: alice -> 30 bob -> 23 josh -> 20 josh -> 30 andy -> 40 andy -> 40 to get only this pairs: alice -> 30 bob -> 23 josh -> 20 andy -> 40
rsk82
  • 28,217
  • 50
  • 150
  • 240