CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384

    STL Map multiple Key-Value Pairs

    Hi*!
    I am working on a DB application. I want to put the retured data into an STL map. I know how to use a map but that has been with one key-value pair.
    Something like
    PHP Code:
    typedef std::map<std::stringstd::stringSomeMap;
    etc etc 
    Now i want to create map that has for every column a key and respective value from the row . So I'll have for every row a new map & for the whole table an array of maps.
    How to do it????
    Or is there a better way to store data in a diff format???
    Secondly whats the difference b/w the map and hash_map????
    Any Comments & suggest are most Welcome!Thanks for your time,
    Regards,
    Usman.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449
    Have you taken a look at this?

    http://dtemplatelib.sourceforge.net/index.htm

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    Thanks for the link, but thats seems a bit lot for me to digest :(. I still would like to use (even though the DTL might be a better option) but downloading and installing and making my other collegues to agree to use this is a **** lot of a thing :(. If you can please guide how this can achived by just using STL, coz if there are performance drawbacks then we'll be foreced to switch to one you posted. But for the time being, i want to stick to STL map.
    Thanks for your time,
    Regards,
    Usman.

  4. #4
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    Hi!

  5. #5
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347

    Re: STL Map multiple Key-Value Pairs

    Originally posted by usman999_1
    Hi*!
    I am working on a DB application. I want to put the retured data into an STL map. I know how to use a map but that has been with one key-value pair.
    Something like
    PHP Code:
    typedef std::map<std::stringstd::stringSomeMap;
    etc etc 
    Now i want to create map that has for every column a key and respective value from the row . So I'll have for every row a new map & for the whole table an array of maps.
    How to do it????
    Or is there a better way to store data in a diff format???
    I don't know what you really want; it's difficult for me to
    understand, but I think you're saying you want the map's value
    to be another map? If so, you can do whatever you want with
    the STL:
    typedef std::map<someKeyType, someDataType> Value;
    typedef std::map<anotherKeyType, Value> Column;
    typedef std::vector<Column> Table;

    Secondly whats the difference b/w the map and hash_map????
    I'd recommend that you get a good book that tells you about the
    STL. hash_map isn't in the C++ standard like map so using it
    will not be 100% portable. I'm not going to explain it, though; I
    will leave that to the book you choose to read. The two books
    that have helped me the most with the STL are:
    Effective STL by Scott Meyers
    The C++ Standard Library by Nicolai M Josuttis

    You should also have
    The C++ Programming Language by Bjarne Stroustrup

    --Paul

  6. #6
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    Well i got it, I need to use the map bit intelligently.
    Thank you all!
    Usman.
    Last edited by usman999_1; April 11th, 2003 at 06:57 AM.

  7. #7
    Join Date
    Sep 2000
    Location
    Russia
    Posts
    262
    The main difference between map and hash_map is that elements in map are in particular order, that is they are sorted by the key. In hash_map the order of elements is arbitrary (it depends on implementation, the hash-function provided etc.)
    Map is implemented as binary-tree while hash-map is an array of objects with indexes produced by the hash-function for each key value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured