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
5
votes
1 answer

calling .clear() or .erase() on c++ std::multimap sometimes causes freeze (100% cpu)

We are using a multimap for quick value/index lookups, declared like this typedef double Numerical; std::multimap SortableRowIndex; And we fill it up with pairs, using SortableRowIndex.insert(std::pair
5
votes
3 answers

Google Maps API vs Multimap/Bing Maps API

I want to know if anyone who has experience of using both the Google Maps API and the Multimap API can give a good reason as to why one is better than the other - or maybe a list of pros and cons? I will be working on a complete re-development of a…
Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
5
votes
3 answers

Guava ImmutableSortedSetMultimap?

Google Guava has a SortedSetMultimap. Wonderful. Now where is the immutable version? There exists an ImmutableSetMultimap. But what about ImmutableSortedSetMultimap? (Please don't reply with "Why do you want one?")
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
5
votes
3 answers

How can I iterate through a Guava multimap to print out values as pairs

For each key in a Guava Multimap I need to take the corresponding values and make pairs with them that are not dependent on order.Uniqueness of pairs are not dependent on order for make pairs inside of key. [A,B] = [B,A]. If the pair [B,A] is…
user3590149
  • 1,525
  • 7
  • 22
  • 25
5
votes
3 answers

Many-value map in Scala

In Scala 2.8, I have an immutable map with multiple values for each key: Map[T,Iterable[U]] Is there a superior representation? Secondly, how would you generate such a map from Iterable[(T,U)] ? I am presently using: def toGroupedMap[T,U](vals:…
David Crawshaw
  • 10,427
  • 6
  • 37
  • 39
5
votes
3 answers

Iterator invalidation - does end() count as an iterator or not?

I ran into the following problem using std::multimap::equal_range() and insert(). According to both cplusplus.com and cppreference.com, std::multimap::insert does not invalidate any iterators, and yet the following code causes an infinite…
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
5
votes
3 answers

How to iterate over all values() in a QMultiHash

I need to iterate over a QMultiHash and examine the list of values that correspond to each key. I need to use a mutable iterator so I can delete items from the hash if they meet certain criteria. The documentation does not explain how to access…
Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
5
votes
3 answers

primitive multimap in java with good (insert, iteration) performance characteristics

I'm doing some heavy processing (building inverse indices) using ints/ longs in Java. I've determined that (un)boxing of standard java.collections maps takes a big portion of the total processing time. (as compared to a similiar implementation…
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
5
votes
2 answers

Which data structure should i use for my purpose?

I need a data structure just like a map but each key may have multiple values related to it but I need to get all the values corresponding to a single key as an array of the objects. So which data structure would be the best to do this. I don't need…
ab_11
  • 83
  • 1
  • 8
5
votes
5 answers

C++ Iterate from the second element of a map

I have a std::multimap on which I am iterating using a forward iterator. std::multimap::iterator it; for(it=map.begin();it!=map.end();++it) { // do something } Now I need to treat the first element differently and start iterating from…
ACC
  • 2,488
  • 6
  • 35
  • 61
4
votes
1 answer

Guava: construct a Multimap by inverting a Map

why does Guava doesn't have the following factory call to create a MultiMap from a normal Map? public static MultiMap invertMap(Map map); I have program-names mapped to an integer of how often they were called. I'd like to invert…
Fabian Zeindl
  • 5,860
  • 8
  • 54
  • 78
4
votes
3 answers

Freemarker: how to use Multimap (or Map of Lists)

I'm trying to use a com.google.common.collect.Multimap from Freemarker. In a Multimap, for each key in the map, you get back Collection. I tried the following but it didn't work: Java: context.put("itemsByCategory",…
Erik
  • 997
  • 4
  • 14
  • 24
4
votes
3 answers

Kotlin transform List>> into Multimap

I'm looking for an idiomatic way of converting a list of pairs where Pair.first is a key and Pair.second is a list of values. This procedural approach works but I was hoping to find a more idiomatic way that doesn't require creating the mutable…
dcompiled
  • 4,762
  • 6
  • 33
  • 36
4
votes
4 answers

Scala multimap: get item or else empty set

if I'm using the Scala Multimap, and I want to get the values associated with a key or else the empty set, do I have to write the following? multimap.getOrElse("key", new collection.mutable.HashSet()) It would seem that the following should just…
schmmd
  • 18,650
  • 16
  • 58
  • 102
4
votes
1 answer

Haskell -- what to use for a labelled set partition?

Beginner question -- what do you usually use as a multimap? I want a function that takes a labelling function and partitions elements by each label. For example, f x | x `mod` 2 == 0 = EVEN | otherwise = ODD the output of partition f lst where…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143