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

How to avoid duplicate pairs / find a pair in multimap?

I have some (working) code that uses a multimap. I'd like to change it to disallow duplicate values on the same key (obviously different values on the same key are fine, otherwise I wouldn't use a multimap). Surprisingly the type…
Qwertie
  • 16,354
  • 20
  • 105
  • 148
8
votes
1 answer

How to sort guava multimap? (KEY=DATE)

I have a Multimap multimap = ArrayListMultimap.create(); from guava. I was wondering how to SORT the the Date key in the multimap. Currently, I'm doing this: Iterator dateItr = multimap.keySet().iterator(); …
adhg
  • 10,437
  • 12
  • 58
  • 94
7
votes
2 answers

Adding array values to std::multimap

I am trying to use a multimap with an integer key and values made of array of integers with 2 elements. typedef std::multimap reverseHeightMap; reverseHeightMap container; When I try to add values like this: container.insert(…
Andrea Casaccia
  • 4,802
  • 4
  • 29
  • 54
7
votes
2 answers

How to iterate/count for a multimap

My class is like this: class Outgoing { multimap outgoing; public: void makeConnection(string key, string value) { outgoing.insert(pair(key,value)); } void iterate() { …
Anon
  • 2,608
  • 6
  • 26
  • 38
7
votes
1 answer

Collect Lines using Multimap Collector

Is there a way to covert the below to using collectors yet? List lines = getLines(); Multimap multimap = ArrayListMultimap.create(); lines.forEach(line -> multimap.put(line[0],line[1]); );
user1870035
7
votes
2 answers

Recursive traversal of a dictionary in python (graph traversal)

I have a dictionary with the following structure: KEY VALUES v1 = {v2, v3} v2 = {v1} v3 = {v1, v5} v4 = {v10} v5 = {v3, v6} The values of a key are actually links to other keys. By using the values I want to reach the other keys till the…
Hani Goc
  • 2,371
  • 5
  • 45
  • 89
7
votes
2 answers

How can I compare two MultiMaps?

I have two Multimaps which have been created from two huge CSV files. Multimap mapOne = ArrayListMultimap.create(); Multimap mapTwo = ArrayListMultimap.create(); I have assumed one CSV column to be…
user3044240
  • 621
  • 19
  • 33
7
votes
1 answer

How do multimaps internally handle duplicate keys?

With maps, I can understand it being implemented as a binary search tree (a red/black tree, for example) and the time complexity of it. But with multimaps, how are key collisions handled internally? Is it that a list is maintained for all the nodes…
basav
  • 1,475
  • 12
  • 20
7
votes
3 answers

Spring MVC configuration + Jackson + Guava multimap

I'm struggling with this: We have a Table class with a Guava multimap (simplified code, basically 1 member, 2 constructors, getter and setter for the multimap): public class Table { private LinkedHashMultimap fields; public…
Pablo
  • 203
  • 2
  • 8
7
votes
2 answers

Bidirectional multimap equivalent data structure

I know that Guava has a BiMultimap class internally but didn't outsource the code. I need a data structure which is bi-directional, i.e. lookup by key and by value and also accepts duplicates. i.e. something like this: (in my case, values are…
Bernice
  • 2,552
  • 11
  • 42
  • 74
7
votes
2 answers

Efficiently count number of entries between two std::multimap iterators

I would like to count the number of entries between two iterators of an std::multimap in less than O(N) time. Are there any tricks or clever ways to do this? Since std::multimap has bidirectional iterators, my understanding is that something like…
skyw
  • 349
  • 4
  • 15
6
votes
2 answers

Fast MultiMap in Multi-Thread Environments

I am currently using Guava Multimap implementation. map = Multimaps.synchronizedSetMultimap(HashMultimap. create()); However I found that my program performance is now bounded by the synchronization block synchronized (mutex) used in…
CHANist
  • 1,302
  • 11
  • 36
6
votes
4 answers

c++ Why std::multimap is slower than std::priority_queue

I implemented an algorithm where I make use of an priority queue. I was motivated by this question: Transform a std::multimap into std::priority_queue I am going to store up to 10 million elements with their specific priority value. I then want to…
Kaspatoo
  • 1,223
  • 2
  • 11
  • 28
6
votes
3 answers

How can I create a Multimap in Java on Android

Where can I find an implementation of multimap for Java that will work on Android without having to include any other classes etc. The implementations I've found all require other things which require other things and it gets messy quick. I'm…
ima747
  • 4,667
  • 3
  • 36
  • 46
6
votes
3 answers

Priority Queue using MultiMap - Java

I have to implement Priority Queue using MultiMap. I use MultiMap from Google Collections. The following code creates a MultiMap and adds few elements into it. Multimap multimap = HashMultimap.create(); …
Devel
  • 950
  • 9
  • 17
  • 29