bimap

boost::bimap for enum

旧时模样 提交于 2019-12-06 01:41:34
问题 I'm trying to create a simple bi-directional lookup facility for enums in C++. I have one-way lookup working fine... enum MyEnum { One, Two, Three }; const boost::unordered_map<MyEnum,std::string> MyEnumMap = map_list_of (One, "One") (Two, "Two") (Three, "Three"); and then doing a look via MyEnumMap.at(One) That works but it only allows for lookups based on key. I'd like to use a bi-directional lookup container such as boost:bimap to allow for easy reverse lookups based on value as well as

Java: Instantiate Google Collection's HashBiMap

≡放荡痞女 提交于 2019-12-04 03:29:57
问题 I'm using Eclipse, and I've added google-collect.1.0-rc2.jar as a referenced library. Yet somehow this still doesn't work: import com.google.common.collect.HashBiMap; public class Odp { //... HashBiMap<Character, Integer> charOcc = HashBiMap<Character, Integer>.create(); } Eclipse gives the following errors: Multiple markers at this line HashBiMap cannot be resolved Character.Integer cannot be resolved Syntax error on token ",", "." expected Syntax error on token ".", delete this token The

Boost::Bimap equivalent of bidirectional multimap

China☆狼群 提交于 2019-12-02 22:55:51
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 in the other direction, can this be done using boost::bimap ? Has anyone experience of this or can point me to the correct page ? ForEveR All is in documentation... http://www.boost.org/doc/libs/1_51_0/libs/bimap/doc/html/boost_bimap/the_tutorial/discovering_the_bimap_framework.html typedef boost::bimap<bimaps::multiset_of<int>, bimaps::set_of<int>>

What is the best Guava (Google) collection API to represent direct or inverse relationship between two or multiple factors?

别等时光非礼了梦想. 提交于 2019-12-02 00:35:59
问题 BiMap do have inverse method but I am not sure it is a right collection to use for the problem. Can someone please suggest alternative approach or collection/method? An example would be helpful. Thanks in advance. Prakash 回答1: Could you show a simple code sample of how you would use such a data structure? Should keys / values be unique? In this case, BiMap sounds about right. If keys / values are not unique, you want some kind of "BiMultimap" (also called a "graph"), as discussed in this

Java: Instantiate Google Collection's HashBiMap

☆樱花仙子☆ 提交于 2019-12-01 18:17:12
I'm using Eclipse, and I've added google-collect.1.0-rc2.jar as a referenced library. Yet somehow this still doesn't work: import com.google.common.collect.HashBiMap; public class Odp { //... HashBiMap<Character, Integer> charOcc = HashBiMap<Character, Integer>.create(); } Eclipse gives the following errors: Multiple markers at this line HashBiMap cannot be resolved Character.Integer cannot be resolved Syntax error on token ",", "." expected Syntax error on token ".", delete this token The method create() is undefined for class Odp What am I doing wrong? Other Google stuff, like Joiner, works

Variadic typedefs, or “Bimaps done the C++0x way”

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 19:12:47
Short question: Can I typedef a variadic argument pack? I need template <typename ...T> struct Forward { typedef T... args; }; . Long version: I was thinking about reimplementing the excellent boost bimap in C++0x. Recall that a bimap of two types S and T is a std::set of relations between S x and T y . The objects themselves are stored in two independent internal containers, and the relations track the associated iterators I suppose; both types can serve as keys via "left" and "right" lookup. Depending on the choice of internal containers, values may be unique or not, e.g. if the left

Guava: java.lang.NoClassDefFoundError - com.google.common.collect.HashBiMap

放肆的年华 提交于 2019-11-30 13:41:54
I currently face the problem of java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap when using guava libraries downloaded from here: http://code.google.com/p/guava-libraries/ I already add guava-12.0.jar into my project as a reference library but I still get the error. May you give some advice on what the problem would be? Thankyou for your help package my.project; import android.app.Activity; import android.os.Bundle; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; public class MainActivity extends Activity{ private BiMap<String,String>

Guava: java.lang.NoClassDefFoundError - com.google.common.collect.HashBiMap

为君一笑 提交于 2019-11-29 19:05:03
问题 I currently face the problem of java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap when using guava libraries downloaded from here: http://code.google.com/p/guava-libraries/ I already add guava-12.0.jar into my project as a reference library but I still get the error. May you give some advice on what the problem would be? Thankyou for your help package my.project; import android.app.Activity; import android.os.Bundle; import com.google.common.collect.BiMap; import com.google

Do we have a MultiBiMap ?

江枫思渺然 提交于 2019-11-29 10:51:07
As we now, there is the concept of BiMap and multiMap but is there a multiBiMap ? so what do I mean by this. In multiMap you have one-to-many relationship between K and V, a single key can be associated to multiple value, hence the name. In bi map you have K,V pair which is bi-directional mean you can get V,K relationship as well. Like having a two regular maps but synchronized. I need a bi directional multi map where you combine these two concepts. import java.util.Set; import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; public class ManyToMany<K, V> {

Is there a Boost.Bimap alternative in c++11?

淺唱寂寞╮ 提交于 2019-11-29 09:05:59
Is there a usable alternative to Boost's bimap in C++0x? I would like to avoid Boost, but fully embrace C++11. If necessary, a slimmed down version of Boost's bimap would work for me (I need a constant bimap to switch between enums and corresponding strings) throughout my program. The map will be compile-time constant, so perhaps even two manually maintained maps aren't the optimal solution. Thanks! UPDATE: I found this on The Code Project, but it seems licensing may be an issue: http://www.codeproject.com/KB/stl/bimap.aspx?fid=12042&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=151#xx0xx I