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. C / C++ / MFC
  4. 2-Way StringToString Map

2-Way StringToString Map

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
8 Posts 5 Posters 3 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.
  • S Offline
    S Offline
    Sprudling
    wrote on last edited by
    #1

    I want to "connect" two strings together. Like MFC's CMapStringToString, just both ways, and I'm not using MFC. There should be no limit to how many strings that can be stored. Btw, I've made my own little string-class, so only need a method for mapping them together. I also want the method to be fast, so iteration through a huge list of strings is not something I want to do. Anyone got an elegant solution...? :confused: Sprudling ;)

    S M T 3 Replies Last reply
    0
    • S Sprudling

      I want to "connect" two strings together. Like MFC's CMapStringToString, just both ways, and I'm not using MFC. There should be no limit to how many strings that can be stored. Btw, I've made my own little string-class, so only need a method for mapping them together. I also want the method to be fast, so iteration through a huge list of strings is not something I want to do. Anyone got an elegant solution...? :confused: Sprudling ;)

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      Use a single list or array to store all the strings. Be sure each entry is unique. Then use one map to map the indices/pointers to each other in whatever combinations are appropriate. This should be pretty fast, since the strings are only stored once, and string comparisons need only be made when new strings are added to the list. And if words were wisdom, I'd be talking even more.

      The Offspring, I Choose

      C 1 Reply Last reply
      0
      • S Sprudling

        I want to "connect" two strings together. Like MFC's CMapStringToString, just both ways, and I'm not using MFC. There should be no limit to how many strings that can be stored. Btw, I've made my own little string-class, so only need a method for mapping them together. I also want the method to be fast, so iteration through a huge list of strings is not something I want to do. Anyone got an elegant solution...? :confused: Sprudling ;)

        M Offline
        M Offline
        Matt Weagle
        wrote on last edited by
        #3

        You could also look at the STL's pair<>.

        1 Reply Last reply
        0
        • S Shog9 0

          Use a single list or array to store all the strings. Be sure each entry is unique. Then use one map to map the indices/pointers to each other in whatever combinations are appropriate. This should be pretty fast, since the strings are only stored once, and string comparisons need only be made when new strings are added to the list. And if words were wisdom, I'd be talking even more.

          The Offspring, I Choose

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It would not be fast at all if it was a list. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

          S 1 Reply Last reply
          0
          • S Sprudling

            I want to "connect" two strings together. Like MFC's CMapStringToString, just both ways, and I'm not using MFC. There should be no limit to how many strings that can be stored. Btw, I've made my own little string-class, so only need a method for mapping them together. I also want the method to be fast, so iteration through a huge list of strings is not something I want to do. Anyone got an elegant solution...? :confused: Sprudling ;)

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #5

            You'll need a containter for strings and two maps - one for each 'way'. STL classes will be OK for that. Aggregate these objects into one class, provide an interface - that's all. Tomasz Sowinski -- http://www.shooltz.com

            1 Reply Last reply
            0
            • C Christian Graus

              It would not be fast at all if it was a list. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

              S Offline
              S Offline
              Shog9 0
              wrote on last edited by
              #6

              why is this? And if words were wisdom, I'd be talking even more.

              The Offspring, I Choose

              C 1 Reply Last reply
              0
              • S Shog9 0

                why is this? And if words were wisdom, I'd be talking even more.

                The Offspring, I Choose

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Because you'd have indices into a container to look up the actual strings, and list lookups require walking the list, they are slow compared to arrays which have instant lookup. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

                S 1 Reply Last reply
                0
                • C Christian Graus

                  Because you'd have indices into a container to look up the actual strings, and list lookups require walking the list, they are slow compared to arrays which have instant lookup. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002

                  S Offline
                  S Offline
                  Shog9 0
                  wrote on last edited by
                  #8

                  :eek: ! :eek: Yes that would be slow. For a list i think you'd want to go with pointers. And if words were wisdom, I'd be talking even more.

                  The Offspring, I Choose

                  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