Board index » cppbuilder » STL hashing algorithms

STL hashing algorithms


2005-04-01 05:23:33 PM
cppbuilder83
Not sure if this is the best place to post this - where else would STL
questions be answered?
I currently use a TStringList for fast lookups of objects but I feel
that this is sub-optimal, especially for large lists.
Does anyone have any experience on STL classes and can suggest any
alternatives. I have several thousand strings in the table and feel
that a hashed lookup would be better. Are there any hashing STL
functions available? The help for the STL is somewhat limited.
Cheers, Pete
 
 

Re:STL hashing algorithms

Hello Pete,
imho a map is what you need:
#include <map>
std::map<AnsiString, int>MyMap;
MyMap["Key1"] = 1;
MyMap["Key2"] = 0;
MyMap["Key2"] = 1;
if (MyMap["Key2"] == 1)
DoSomething();
The example above is a simple map with an AnsiString key and an integer
value.
Of course you are completely free to choose whatever type you want, because
the container classes are all templates.
Hope this helps,
best regards,
Gunther
"Pete Fraser" < XXXX@XXXXX.COM >schrieb im
Newsbeitrag news: XXXX@XXXXX.COM ...
Quote
Not sure if this is the best place to post this - where else would STL
questions be answered?
I currently use a TStringList for fast lookups of objects but I feel
that this is sub-optimal, especially for large lists.
Does anyone have any experience on STL classes and can suggest any
alternatives. I have several thousand strings in the table and feel
that a hashed lookup would be better. Are there any hashing STL
functions available? The help for the STL is somewhat limited.
Cheers, Pete
 

Re:STL hashing algorithms

Pete Fraser < XXXX@XXXXX.COM >writes:
Quote
Not sure if this is the best place to post this - where else would STL
questions be answered?
.language.cpp seems to be the obvious choice. The STL is not a
third-party tool but part of the Standard C++ Library.
Quote
The help for the STL is somewhat limited.
Cf.
www.sgi.com/tech/stl/
www.stlport.com/
If you are using C++ Builder 6, there should be hash_map and hash_set
templates (and their multi siblings). These are not Standard C++
containers, but similar containers have been voted into the Standard
to come as unordered_map etc.
 

{smallsort}