multimap

How to create a Multimap<K,V> from a Map<K, Collection<V>>?

*爱你&永不变心* 提交于 2019-11-26 18:14:40
问题 I didn't find such a multimap construction... When I want to do this, I iterate over the map, and populate the multimap. Is there an other way? final Map<String, Collection<String>> map = ImmutableMap.<String, Collection<String>>of( "1", Arrays.asList("a", "b", "c", "c")); System.out.println(Multimaps.forMap(map)); final Multimap<String, String> expected = ArrayListMultimap.create(); for (Map.Entry<String, Collection<String>> entry : map.entrySet()) { expected.putAll(entry.getKey(), entry

how does the stl's multimap insert respect orderings?

谁说我不能喝 提交于 2019-11-26 17:11:10
问题 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 through it. This sounds like std::multimap is just what I need. However, I also need data with the same index to be kept in the order in which it was inserted, in this case meaning that when I iterate through the data I get to the earlier data before

Having a Multimap sorted on keys only in Java

試著忘記壹切 提交于 2019-11-26 16:58:32
问题 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 MyObject /* doesn't implement Comparable */ { private String name; private int score; // Getters/setters are implemented public static Function<MyObject,Integer> myObjectToScore { @Override public Integer apply (MyObject o) { return o.score; } }

stl::multimap - how do i get groups of data?

社会主义新天地 提交于 2019-11-26 16:04:10
Multimap essentially has groups of data sorted by the key. I want a method by which I could access these individual groups and get their aggregate values. For example, in a std::multimap< string, int > I store {"Group1", 1}, {"Group1", 2}, {"Group1", 3}, {"Group2", 10}, {"Group2", 11}, {"Group2", 12} Having stored these values, I should be able to iterate this multimap and get the aggregate values of each "group". Problem is there aren't any functions defined in STL to access MultiMaps in such a way. I could use lower_bound , upper_bound to manually iterate the multimap and total the group's

Bidirectional multi-valued map in Java

心不动则不痛 提交于 2019-11-26 12:31:08
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. For example, it needs to be able to hold pairs like: "s1"->1, "s2"->1, "s3"->2, and I need to be able to get the value mapped to each key, and for each value, get all the keys associated with it. So you need support for many-to-many relationships? Closest you can get is Guava 's Multimap like @Mechkov wrote - but more specifically Multimap

is there an iterator across unique keys in a std::multimap?

拜拜、爱过 提交于 2019-11-26 11:20:44
问题 Is there a simple or standard way to have a multimap iterator which iterate across unique keys in a multimap? i.e. for a set that looks like: {1, \"a\"}, {1, \"lemon\"}, {2, \"peacock\"}, {3, \"angel\"} an iterator which would start at {1, \"a\"} then incrementing would point to {2, \"peacock\"} and then incrementing again would point to {3, \"angel\"} ? 回答1: You can use upper_bound to increment the iterator position instead of ++ : #include <map> #include <string> #include <iostream> using

stl::multimap - how do i get groups of data?

為{幸葍}努か 提交于 2019-11-26 04:41:13
问题 Multimap essentially has groups of data sorted by the key. I want a method by which I could access these individual groups and get their aggregate values. For example, in a std::multimap< string, int > I store {\"Group1\", 1}, {\"Group1\", 2}, {\"Group1\", 3}, {\"Group2\", 10}, {\"Group2\", 11}, {\"Group2\", 12} Having stored these values, I should be able to iterate this multimap and get the aggregate values of each \"group\". Problem is there aren\'t any functions defined in STL to access

Duplicate keys in .NET dictionaries?

余生颓废 提交于 2019-11-26 03:05:30
问题 Are there any dictionary classes in the .NET base class library which allow duplicate keys to be used? The only solution I\'ve found is to create, for example, a class like: Dictionary<string, List<object>> But this is quite irritating to actually use. In Java, I believe a MultiMap accomplishes this, but cannot find an analog in .NET. 回答1: If you're using .NET 3.5, use the Lookup class. EDIT: You generally create a Lookup using Enumerable.ToLookup. This does assume that you don't need to

Bidirectional multi-valued map in Java

纵饮孤独 提交于 2019-11-26 02:58:56
问题 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. For example, it needs to be able to hold pairs like: \"s1\"->1, \"s2\"->1, \"s3\"->2, and I need to be able to get the value mapped to each key, and for each value, get all the keys associated with it. 回答1: So you need support for many-to-many

multimap in .NET

雨燕双飞 提交于 2019-11-26 02:34:51
问题 I need an equivalent to c++\'s std::multimap<K, V, Comp, Alloc> in C-sharp. Does it exist in the standard library? 回答1: Because it's almost christmas :) ////////////////////////////////////////////////////////////////////// // Algorithmia is (c) 2008 Solutions Design. All rights reserved. // http://www.sd.nl ////////////////////////////////////////////////////////////////////// // COPYRIGHTS: // Copyright (c) 2008 Solutions Design. All rights reserved. // // The Algorithmia library sourcecode