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

Bidirectional multi-valued map in Java

I am looking for a way to store key-value pairs. I need the lookup to be bidirectional, but at the same time I need to store multiple values for the same key. In other words, something like a BidiMap, but for every key there can be multiple values.…
Bojana Popovska
  • 571
  • 1
  • 4
  • 15
27
votes
7 answers

How can I get all the unique keys in a multimap

I have a multimap and I want get all the unique keys in it to be stored in a vector. multimap mymm; multimap::iterator it; char c; mymm.insert(pair('x',50)); mymm.insert(pair('y',100)); …
AJ.
  • 2,561
  • 9
  • 46
  • 81
26
votes
2 answers

How to build a multimap from a list of tuples in Scala?

Suppose I have a list of tuples List[(A, B)]. What is the best way to convert it to a multimap, which maps A to Set[B]? Can I build an immutable multimap ?
Michael
  • 10,185
  • 12
  • 59
  • 110
26
votes
8 answers

Having a Multimap sorted on keys only in Java

I would like to have a c.g.c.c.Multimap that is sorted based on keys only. The values shouldn't be sorted. I've tried to build something with guava's TreeMultimap, but I can't use it because the value type doesn't implement Comparable. public class…
Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
26
votes
13 answers

Multi-valued hashtable in Java

Is it possible to have multiple values for the same key in a hash table? If not, can you suggest any such class or interface which could be used?
raji
23
votes
7 answers

Why does multimap allow duplicate key-value pairs?

EDIT: Please note, I'm NOT asking why multimap can't contain duplicate keys. What's the rationale behind multimap allowing duplicate key-value pairs? (not keys) #include #include #include int main(int argc, char** argv) { …
Alex B
  • 82,554
  • 44
  • 203
  • 280
23
votes
7 answers

how does the stl's multimap insert respect orderings?

I have some data which come with a integer index. I am continuous generating new data which needs to added to the collection of data I have, sorted by that index, at the same time I want to easily be able to go the start of the data and iterate…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
22
votes
7 answers

Is there an alternative to Dictionary/SortedList that allows duplicates?

Possible Duplicate: C# Sortable collection which allows duplicate keys Basically I'd like to make a Dictionary work with duplicate keys without going into custom comparer implementations. There is an idea of: Dictionary> but…
Sedat Kapanoglu
  • 46,641
  • 25
  • 114
  • 148
22
votes
6 answers

How to achieve this Map> structure

I have data like below: Key value ----- ------ car toyota car bmw car honda fruit apple fruit banana computer acer computer asus computer ibm ... (Each row of above data is an object with…
Mellon
  • 37,586
  • 78
  • 186
  • 264
21
votes
4 answers

Why is using a std::multiset as a priority queue faster than using a std::priority_queue?

I try to replace std::multiset with std::priority_queue. But I was dissapointed with the speed results. Running time of the algorithm increase by 50%... Here are the corresponding commands: top() = begin(); pop() = erase(knn.begin()); push() =…
Johny
  • 323
  • 2
  • 3
  • 5
20
votes
1 answer

Idiomatically creating a multi-value Map from a Stream in Java 8

Is there any way to elegantly initialize and populate a multi-value Map> using Java 8's stream API? I know it's possible to create a single-value Map using the Collectors.toMap(..) functionalities: Stream persons =…
errantlinguist
  • 3,658
  • 4
  • 18
  • 41
20
votes
2 answers

Boost::Bimap equivalent of bidirectional multimap

First part of the question is that I am trying to use boost::bimap, but from the documentation it is unclear to me how to define a bidirectional multimap. The second part of the question is that I need it to be a map in one direction and a multimap…
BlueTrin
  • 9,610
  • 12
  • 49
  • 78
19
votes
6 answers

multimap vs map with set

I'm wondering which is more efficient. std::map< String, std::set > or std::multimap< String, int > EDIT: I do not plan on doing anything out of the ordinary with these maps. Standard insert, delete, modify, search. The size of each set or…
Kaiser Wilhelm
  • 618
  • 9
  • 24
18
votes
2 answers

Adding a key with an empty value to Guava Multimap

I have a need to add a key to a Guava Multimap with an empty collection as the value. How do I accomplish this? I tried this: map.put( "my key", null ); but calling get() returns a list with one element, which is null. I worked around this by…
Ryan Nelson
  • 4,466
  • 5
  • 29
  • 45
17
votes
2 answers

Convert Guava HashMultimap to json

I want to print HashMultiMap as json. HashMultimap multimap = HashMultimap.create(); multimap.put("a",Obj1); multimap.put("a",Obj3); multimap.put("b",Obj2); to { "a":[Obj1,Obj3], "b":[Obj2] } Obj1 and other objects should again…
sat
  • 40,138
  • 28
  • 93
  • 102
1
2
3
51 52