Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Possible to have a two-way Associative Arrays

Possible to have a two-way Associative Arrays

Scheduled Pinned Locked Moved ATL / WTL / STL
data-structuresquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ComplexLifeForm
    wrote on last edited by
    #1

    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 :) :)

    A S C 3 Replies Last reply
    0
    • C ComplexLifeForm

      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 :) :)

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Like this[^]? :-)

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      K 1 Reply Last reply
      0
      • C ComplexLifeForm

        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 :) :)

        A Offline
        A Offline
        Andy Moore
        wrote on last edited by
        #3

        Look at boost::bimap. http://www.boost.org/doc/libs/1_39_0/libs/bimap/doc/html/index.html[^]

        Pax Domini sit semper vobiscum

        S 1 Reply Last reply
        0
        • A Andy Moore

          Look at boost::bimap. http://www.boost.org/doc/libs/1_39_0/libs/bimap/doc/html/index.html[^]

          Pax Domini sit semper vobiscum

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C ComplexLifeForm

            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 :) :)

            C Offline
            C Offline
            ComplexLifeForm
            wrote on last edited by
            #5

            Thank you Andy and Stuart for the reply. I was looking for boost bi-map type functionality. Regards :) :)

            1 Reply Last reply
            0
            • S Stuart Dootson

              Like this[^]? :-)

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              K Offline
              K Offline
              Kevin McFarlane
              wrote on last edited by
              #6

              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

              S 1 Reply Last reply
              0
              • K Kevin McFarlane

                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

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups