tags:

views:

5101

answers:

12

I am trying to use the SGI STL implementation I have downloaded from their site. I want to use a hashmap, because I have to store around 5.000.000 records, but it should be good: I need to be able to access it very quickly. I've tried stedext::hash_map, but it was very slow because I couldn't set the initial size. By the way, is it possible to do that? If I add the additional path to my MS Visual Studio, I can't even compile the example from the SGI site. I get an error message:

error C2061: syntax error : identifier 'T'.

Has anyone else faced such problems?

A: 

I have used it a number of times without problems, though I used it with gcc (both on windows and linux) and not Visual Studio.

For actual usage, the documentation is here.

You can specify how many buckets to reserve using

void resize(size_type n)

Regarding your issue with identifier T, I assume you have forgotten to replace a template argument, named T, with an actual type. If you can't figure it out, maybe paste a code snippet of how you are using the hash_map.

Example from the documentation:

#include <hash_map>
#include <iostream>

struct eqstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) == 0;
  }
};

int main()
{
  std::hash_map<const char*, int, hash<const char*>, eqstr> months;

  months["january"] = 31;
  months["february"] = 28;
  months["march"] = 31;
  months["april"] = 30;
  months["may"] = 31;
  months["june"] = 30;
  months["july"] = 31;
  months["august"] = 31;
  months["september"] = 30;
  months["october"] = 31;
  months["november"] = 30;
  months["december"] = 31;

  std::cout << "september -> " << months["september"] << endl;
  std::cout << "april     -> " << months["april"] << endl;
  std::cout << "june      -> " << months["june"] << endl;
  std::cout << "november  -> " << months["november"] << endl;
}

Of course, you can use std::string instead of char* if you wish:

std::hash_map<std::string, int, hash<std::string>, eqstr> months;
Dan
A: 

I try to use the example source, you've pasted, but I am not too familiar with templates. This source should be compiled without an error? Using this I get the error related to identifier T.

I did not try it, but yes, it should compile without error.Regarding templates, sometimes a class (or function) is defined something like: template <class T> class Foo ... and you would use it something like Foo<int> ...
Dan
In the case of hash_map, you use templates to specify the type of the key and value as well as the hash function and the comparison operator: std::hash_map<Key, Value, HashFunc, Comp>, in the example code I posted: std::hash_map<const char*, int, hash<const char*>, eqstr>
Dan
A: 

Now the following error message appears during compile:

error C2061: syntax error : identifier '_CountofType'

I have opened a new, empty C++ project, added a new cpp file and added an additional directory to a project where the SGI STL is.

I have no idea why you are seeing that. I assume it is a problem with adding the SGI STL implementation to Visual Studio. Since I don't have Visual Studio on this computer, I can't verify this.
Dan
It's funny, because I've downloaded Dev-CC and I have pasted the same code and it's running...
A: 

Are there any other error messages showing up when you try to build/compile your project?
You mentioned you...

added an additional directory to a project where the SGI STL is.

Could you expand on that a bit? There are many places you can add directories in visual studio project settings. i.e. adding additional include header paths, additional library paths, etc. Where did you add your directory?

Rob Segal
A: 

No, that is the only error message I've got. I've changed the project property, on Project Property Page dialog box (From Project->Property menu), Configuration Properties->C\C++->General, and there is a label Additional Include Directories and there I have chosen the path of SGI STL. I've the configuration from dropdown-list, to All Configuartions. That's what I've made. Were these things right?

A: 

That sounds reasonable. What is the structure of your STL directory? Did you get all the SGI STL files from their website or just a single one? It could be that you're missing a dependency file which is resulting in the error you are seeing.

Rob Segal
A: 

I've dowloaded the zipped version of this library, there are only header files in that zip. There is another option under Linker, it is calles additional dependencies, but there are only *.lib files there. The command line of my settings looks:

/Od /I "C:\SGI" /D "_MBCS" Gm /EHsc /RTC1 /MDd /Fo"Debug\\"/Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt

I don't whether it is more usable....

A: 

Yes you will only find header files, that is indicated on the SGI STL website. As you noticed the link dependencies are for .lib files only so don't bother adding anything there.

You are compiling the example posted by Dan still right? You may need to specify your include headers using quotes rather than brackets. So use...

#include "hash_map"

instead of...

#include <hash_map>

It could be an issue with how include files are being searched for by the compiler. As an additional inquiry what version of Visual Studio are you using?

Rob Segal
A: 

I've chneged the include brackets. I am trying with VS 2005, and 2008, none of them works. I think, the problem should be related to settings which I haven't made. I've tried the same example source with dev-cc with additional include directory setting and it worked.

A: 

As was pointed out in a thread I noticed on a discussion forum about this issue the SGI STL implementation doesn't seem to have been updated in a very long time. On the download page it even mentions 8 Jun 2000 as the last time it was updated. I would suspect getting the SGI STL implementation to work under VS 2005/2008 is more trouble than its worth.

I would suggest checking out some STL alternatives...

Both are updated regularly.

Rob Segal
A: 

Which one to use, if I want to use an implementation with good performance without suffering days to set only the enviroment. Another important thing is the possibility to size the hash map. Thank you soo much, guys, for your fast help, advice and answers!

+1  A: 

I confess I haven't tried it for myself, but VS2008 is supposed to support TR1 which contains:

#include <tr1/unordered_map>

it's in a "feature Pack" release. http://www.microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&amp;displaylang=en