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
10
votes
5 answers

Guava MultiMap and ConcurrentModificationException

I don't understand why I get a ConcurrentModificationException when I iterate through this multimap. I read the following entry, but I am not sure if I understood the whole thing. I tried to add a synchronized block. But my doubt is what to…
Antoine Claval
  • 4,923
  • 7
  • 40
  • 68
9
votes
1 answer

Create Weak Multimap with Google Collections

Is there an equivalent to the nice MapMaker for MultiMaps? currently i create the cache like this: public static Map> personCache = new MapMaker().weakKeys().makeMap(); the whole point of MultiMap is to avoid the nested…
Andreas Petersson
  • 16,248
  • 11
  • 59
  • 91
9
votes
1 answer

Android Room Multimap issue for the same column names

As stated in official documentation, it's preferable to use the Multimap return type for the Android Room database. With the next very simple example, it's not working correctly! @Entity data class User(@PrimaryKey(autoGenerate = true) val _id: Long…
Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48
9
votes
2 answers

emplace_hint performance when hint is wrong

I am trying to determine if emplace_hint should be used to insert a key into a multimap (as opposed to regular emplace). I have already calculated the range of the key in an earlier operation (on the same key): range = multimap.equal_range(key);…
9
votes
1 answer

Does Each Element of a multimap Contain Both the Key and Value?

I can't imagine this hasn't been asked, but I'm not having any luck finding it. Does each element of a multimap contain its value and its key? That is does the internal structure of a multimap look like more like this: map> Or…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
9
votes
3 answers

Multimap in Hibernate

I need a collection that stores entries as key-value pairs (so I can look up values by a key), but I need one that allows multiple values to share the same key using hibernate
vyom
  • 89
  • 1
  • 2
9
votes
2 answers

How do I get the most frequent word in a Map and it's corresponding frequency of occurrence using Java 8 streams?

I have a class IndexEntry which looks like this: public class IndexEntry implements Comparable { private String word; private int frequency; private int documentId; ... //Simple getters for all properties public…
Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
9
votes
2 answers

Can I rely on the order of an unordered map?

I have an std::unordered_multimap and I want to get the last inserted element of a specific key. I observed this behaviour: #include #include #include using namespace std; int main() { …
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
9
votes
1 answer

How to iterate through a multimap and print values grouped by key?

I have std::multimap dataMap; where the keys are MyObject.name and all MyObjects are stored in a std::vector. After filling the map I need to print the contents of dataMap grouped by the same key, where I first need…
jabk
  • 1,388
  • 4
  • 25
  • 43
9
votes
2 answers

Multimap with HashMultiset for values

I'm trying to have a (hash-based) Multimap with a (hash-based) Multiset of values for each key. See the example: Multimap mmap = Multimaps.newMultimap( Maps.>newHashMap(), new…
Dimitris Andreou
  • 8,806
  • 2
  • 33
  • 36
9
votes
2 answers

C++ Find the number of elements in a range from an STL::multimap

I have a STL::multimap and I search it with equal_range to return an upper and lower bound. Can I find the number of elements in this range without iterating through them all and counting them one by one? #include #include using…
Travis
  • 1,872
  • 1
  • 16
  • 12
9
votes
2 answers

Is there a way to get all keys from a value in a multimap?

Say I have a guava Multimap. I have a value, "Foo", that may belong to one or more keys. Is there any way I can figure out which keys contain an entry "Foo"?
Jason Thompson
  • 4,643
  • 5
  • 50
  • 74
8
votes
2 answers

c++ multimap equal_range found nothing

How can I know the equal_range didn't find any match cases? like: multimap mapdic; pair::iterator,multimap::iterator> ret; // insert some string…
Steven Du
  • 1,681
  • 19
  • 35
8
votes
2 answers

Create and Invert MultiMap w/ Java 8 Streams

How can I convert a Set into a Map> or SetMultimap using Java 8 streams or Multimaps, where Result is: class Result { String name; Set items; } For example, I start with: result1: name:…
mathematician
  • 1,942
  • 5
  • 19
  • 22
8
votes
1 answer

Do we have a MultiBiMap?

As we know, there is the concept of BiMap and MultiMap but is there a MultiBiMap ? so what do I mean by this. In MultiMap you have one-to-many relationship between K and V, a single key can be associated to multiple value, hence the name. In BiMap…
AR5HAM
  • 1,220
  • 11
  • 19