Possible to have a two-way Associative Arrays
-
Hi, I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say My2WayArray _twoWayArray; and I can do the following _twoWayArray["user1"] = 123; _twoWayArray["user2"] = 456; and _twoWayArray[123] = "user1"; _twoWayArray[456] = "user2"; this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided. I don't want to use it anywhere, it is just out of curiosity. While I am posting this question I am trying to figure it out at my end. Thanks and Regards :) :)
-
Hi, I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say My2WayArray _twoWayArray; and I can do the following _twoWayArray["user1"] = 123; _twoWayArray["user2"] = 456; and _twoWayArray[123] = "user1"; _twoWayArray[456] = "user2"; this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided. I don't want to use it anywhere, it is just out of curiosity. While I am posting this question I am trying to figure it out at my end. Thanks and Regards :) :)
-
Hi, I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say My2WayArray _twoWayArray; and I can do the following _twoWayArray["user1"] = 123; _twoWayArray["user2"] = 456; and _twoWayArray[123] = "user1"; _twoWayArray[456] = "user2"; this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided. I don't want to use it anywhere, it is just out of curiosity. While I am posting this question I am trying to figure it out at my end. Thanks and Regards :) :)
Look at boost::bimap. http://www.boost.org/doc/libs/1_39_0/libs/bimap/doc/html/index.html[^]
Pax Domini sit semper vobiscum
-
Look at boost::bimap. http://www.boost.org/doc/libs/1_39_0/libs/bimap/doc/html/index.html[^]
Pax Domini sit semper vobiscum
Bah - you beat me to it by a matter of seconds :-)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi, I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say My2WayArray _twoWayArray; and I can do the following _twoWayArray["user1"] = 123; _twoWayArray["user2"] = 456; and _twoWayArray[123] = "user1"; _twoWayArray[456] = "user2"; this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided. I don't want to use it anywhere, it is just out of curiosity. While I am posting this question I am trying to figure it out at my end. Thanks and Regards :) :)
Thank you Andy and Stuart for the reply. I was looking for boost bi-map type functionality. Regards :) :)
-
It's a pity they don't have something like this in the .NET collection classes. And it doesn't seem to exist in the third party libraries either. :(
Kevin
-
It's a pity they don't have something like this in the .NET collection classes. And it doesn't seem to exist in the third party libraries either. :(
Kevin
Probably be quite difficult to port the approach used in Boost - one of the first comments I saw in the bimap headers was:
// Bimap Core, use mpl magic to find the desired bimap type
Once you're using the words 'mpl' (== C++ template metaprogramming library) and 'magic' together, there's little to no hope of translating the code directly to another language. I suspect some form of code generator would be the best bet (I seem to remember a container generator being written by someone before C# got generics - that would be similar).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p