Link to home
Start Free TrialLog in
Avatar of frey
frey

asked on

standard template libraries

I want to create a hash object. I guess I have to use the map class, but how ?

Can anybody give me the syntax to create such an object (with a char* (or a String class) as key and value), to insert a new key/value pair and to retrieve it.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ilia239
ilia239

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LucHoltkamp
LucHoltkamp

Why do you use CString (it's MFC) and not string (plain STL)?
I would advise to use string, you even included <string>
Luc
LucHoltkamp, I agree with you.
You should use STL strings instead of CString in map<>. But the question was about String class (i've read it as "CString class" :-)).  By the way, MFC has its own CMap class and you can use it instead of map...

Ilia239
map is not quite a hash (table). For hash tables one would expect the average complexity of (lookup) operations to be done in constant time, O(1). With map they are performed in logarithmic time O(log(N)).
True, binary trees (maps) and hash tables hav very different properties and performances. The official STL does not have any hash table container (although many stl implimentations do have an unofficial one, often called "hashmap").  The ANSII/ISO standards committee will be meeting in a few years time to discusss extensions to the standard and will very likely add hash tables to the standard (It is already on the agenda), however the standard cannot be changed before 2007 or something like that.

If you don't want to wait :-), you will have to find a hashmap class or write your own.
ilia, the MFC containers are not something I would advise anyone to use...
They only good thing about them is that they work, but compaired to stl, there are some ugly pieces of code...
Luc