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
17
votes
3 answers

which element will be returned from std::multimap::find, and similarly std::multiset::find?

Most likely this question is a duplicate but I could not find a reference to it. I'm looking at std::multiset::find & std::multimap::find functions and I was wondering which element will be returned if a specific key was inserted multiple…
idanshmu
  • 5,061
  • 6
  • 46
  • 92
17
votes
3 answers

How can I insert elements into a multimap?

I want to set up a multimap in C++ as follows: multimap, vector > mmList; But how can I insert data into it? I tried the following code, but it doesn't compile: mmList.insert(pair, vector("a",…
andre de boer
  • 3,124
  • 3
  • 17
  • 15
14
votes
2 answers

Combine two Maps into a MultiMap

What is the best way to combine two Maps into a single Guava MultiMap in Java? For example: Map1 contains (1, a) and (2, b) Map2 contains (2, c) and (3, d) Then the resulting combined multimap would contain (1, {a}), (2, {b, c}), and (3,…
Jake Walsh
  • 3,669
  • 5
  • 22
  • 28
14
votes
2 answers

Erasing elements in a multimap while iterating

I'm writing a nodal path finding algorithm. I need to run through a multimap and delete elements out of it under certain conditions, but keep iterating through the multimap. Below is my code so far, it seems to work most of the time, but…
jasonlg3d
  • 484
  • 2
  • 7
  • 18
14
votes
3 answers

C++: STL multimap.equal_range()

I've got this code and I cannot understand part where equal_range method returns iterators. I know range is pair object with two multimap objects inside, but what I don't get, is why there is 'for (it = range.first; it != range.second; ++it)' -…
ashur
  • 4,177
  • 14
  • 53
  • 85
14
votes
1 answer

Is there a javascript equivalent of the Multimap data structure?

Multimap is an data structure that maps a key to a list/set of values. Is there a good, unobtrusive js library that implements this data structure? Edit - I know I can implement it "easily" myself, but I believe having it as a standalone abstraction…
ripper234
  • 222,824
  • 274
  • 634
  • 905
13
votes
3 answers

Java Guava combination of Multimap and Cache

Is there any such thing as a combination of Guava's Cache and Multimap functionality available? Essentially, I need a collection where entries expire after a given time such as available in Cache but I have non-unique keys and I need the entries to…
hgus1294
  • 747
  • 14
  • 26
12
votes
2 answers

guava: Best way to iterate over the key->collection entries of a Multimap?

I'm looking for the corresponding way, for Multimap, to iterate over entries of a Map, namely: Map map = ...; for (Map.Entry entry : map.entrySet()) { K k = entry.getKey(); V v = entry.getValue(); } Which of the following is…
Jason S
  • 184,598
  • 164
  • 608
  • 970
12
votes
2 answers

Why is insertion order not preserved in MultiMap?

public class MultiMap_Test { public static void main(String[] args) { Multimap myMultimap = ArrayListMultimap.create(); myMultimap.put("classlabel", "tid"); myMultimap.put("Y", "1"); …
11
votes
1 answer

What is multimap::emplace() and move()?

I was viewing the MSDN doc about multimap and find that it has a member function multimap::emplace(). Below is the example of that member function. int main( ) { using namespace std; multimap m1; pair is1(1,…
MorrisLiang
  • 702
  • 2
  • 7
  • 20
11
votes
1 answer

Jackson JSON - Deserialize Commons MultiMap

i want to serialize and deserialize a MultiMap (Apache Commons 4) using JSON. Piece of code to test: MultiMap map = new MultiValueMap<>(); map.put("Key 1", "Val 11"); map.put("Key 1", "Val 12"); map.put("Key 2", "Val…
JDC
  • 4,247
  • 5
  • 31
  • 74
10
votes
3 answers

Why does it.next() throw java.util.ConcurrentModificationException?

final Multimap terms = getTerms(bq); for (Term t : terms.keySet()) { Collection C = new HashSet(terms.get(t)); if (!C.isEmpty()) { for (Iterator it =…
simpatico
  • 10,709
  • 20
  • 81
  • 126
10
votes
1 answer

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

I have a HashMap. 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…
Dennis
  • 1,805
  • 3
  • 22
  • 41
10
votes
2 answers

Scala Immutable MultiMap

In Scala I would like to be able to write val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster) The underlying Map[Owner,Set[Pet]] should have both Map and Set immutable. Here's a first draft for ImmutibleMultiMap with companion…
10
votes
2 answers

A Java multimap which allows fast lookup of key by value

I have a multimap (like that provided by Guava): Multimap which could be seen logically as: Map> The data in my multimap, has unique keys AND unique values. i.e. There can never be the same value assigned to more than one…
Ben
  • 6,567
  • 10
  • 42
  • 64
1 2
3
51 52