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
6
votes
4 answers

implementing remove on a ConcurrentMultimap without races

I've been looking at the problem of writing a concurrent Multimap, and I have an implementation backed by the Google Guava AbstractSetMultimap and a MapMaker computing map that creates on demand the values-collections as a set view over a…
Joe Kearney
  • 7,397
  • 6
  • 34
  • 45
6
votes
1 answer

How to sort guava Multimap keys in reverse order?

I'm fairly new to Guava API and is trying to sort the keys of a MultiMap in reverse order or descending value. I'm initiating the Map in the following way: ListMultimap> listMultimap =…
Shamik
  • 1,671
  • 11
  • 36
  • 64
6
votes
2 answers

using boost multi_index_container to preserve insertion order

I initially started out using a std::multimap to store many values with the same key, but then I discovered that it doesn't preserve the insertion order among values with the same key. This answer claims it can be done with…
rmeador
  • 25,504
  • 18
  • 62
  • 103
6
votes
3 answers

Is there a sorted java collection which handles duplicates?

I need a collection that behaves something like C++ multimap, but I also need to be able to get elements by a range of keys.
Steinbitglis
  • 2,482
  • 2
  • 27
  • 40
6
votes
1 answer

Unordered_Map Lookup Time

The built in maps and sets in C++ libraries (including unordered_map and multimap) requires that the find function (used to lookup a specific element) utilize an iterator for traversing the elements. The C++ reference site claims that looking up…
DarkKunai99
  • 105
  • 1
  • 4
  • 13
6
votes
1 answer

For a map of objects, can I emplace objects, or just pairs?

I'm using C++ 11 and gcc-4.7.0. I'm looking for an STL solution. I'd like to have an unsorted multimap that contains objects of myClass with short strings as keys. Emplace looks like a good way to put the objects into the map as I construct them,…
Qaz
  • 1,556
  • 2
  • 20
  • 34
6
votes
2 answers

Guava - Can a Multimap be serialized?

I am looking at this API ArrayListMultiMap which implements the Serializable interface. Does that mean I can serialize this object ? Are all Multimap objects serialized ?
Princesh
  • 358
  • 5
  • 6
5
votes
6 answers

C++ multimap iterator invalidation

I'm trying to figure out how std::multimap iterators work, therefore I've created a simple example that shows the substance of my problem. If uncomment case 1, I expect iterator to point to the first element with the key 1, but in reality it prints…
givi
  • 1,883
  • 4
  • 22
  • 32
5
votes
3 answers

std::multimap getting two ranges

I'm using a C++ std::multimap and I have to loop over two different keys. Is there an efficient way to do this other than creating two ranges and looping over those ranges seperately? This is the way im doing it now: std::pair
Kaiser Wilhelm
  • 618
  • 9
  • 24
5
votes
2 answers

Removing from guava (google) Multimap never removes the key itself. Why? How to do so?

I'm using the google collections library from guava, I believe the most recent version. I find that once I remove the final (K, V) pair from the map for a given value of K, the map still contains an entry for K, where V is an empty collection. I…
Puzzled
  • 51
  • 1
  • 3
5
votes
4 answers

Multimap not sorting

I have this multimap built to map the hamming distance of a string to its corresponding string. Since the hamming distance of two strings could be the same, I want them to be sorted in ascending order. However when I print it out, it is not sorted.…
Xann
  • 51
  • 1
  • 2
5
votes
1 answer

Merge Two Guava Multimaps

Is there a way to elegantly merge two guava multimaps with the same key value pairs in java 8? I have tried using .collect(Multimaps.toMultimap()) with no luck.
user1870035
5
votes
4 answers

is there a case insensitive multimap in google collections

I need a multi map which keys are case insensitive. is there such implementation in google collections?
oshai
  • 14,865
  • 26
  • 84
  • 140
5
votes
4 answers

Turn a multimap into set of sets

I have a multimap and I would like to get a set of sets - which would group together all the items of type A in the multimap that share the same key. Is there a built-in way to do this in STL?
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
5
votes
2 answers

Use Multimap instead of Map for sending parameters for Rest Assured Call

I am declaring a variable static Multimap multiList = ArrayListMultimap.create(); and adding values like multiList.put(**key1**,value1) multiList.put(**key1**,value1) multiList.put(**key2**,value3) Now, the request…