Click to See Complete Forum and Search --> : STL Map multiple Key-Value Pairs


usman999_1
April 11th, 2003, 04:44 AM
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

typedef std::map<std::string, std::string> SomeMap;
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.

Paul McKenzie
April 11th, 2003, 05:07 AM
Have you taken a look at this?

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

Regards,

Paul McKenzie

usman999_1
April 11th, 2003, 05:16 AM
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.

usman999_1
April 11th, 2003, 06:16 AM
Hi!

PaulWendt
April 11th, 2003, 06:27 AM
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

typedef std::map<std::string, std::string> SomeMap;
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

usman999_1
April 11th, 2003, 06:37 AM
Well i got it, I need to use the map bit intelligently.
Thank you all!
Usman.

Dmitry Zemskov
April 11th, 2003, 12:24 PM
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.