How to use SGI STL hash_map?

I am trying to use the SGI STL implementation that I downloaded from my site. I want to use a hashmap because I need to store about 5,000,000 records, but that should be good: I need to be able to access it very quickly. I tried stedext::hash_map

it but it was very slow because I couldn't set the initial size. By the way, is it possible to do this? If I add an additional path to my MS Visual Studio, I won't even be able to compile this example from the SGI site. I am getting the error:

error C2061: syntax error : identifier 'T'.

      

Has anyone else encountered such problems?

0


source to share


7 replies


I confess I haven't tried this for myself, but VS2008 should support TR1 which contains:

#include <tr1/unordered_map>

      



in the Feature Pack. http://www.microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&displaylang=en

+2


source


I have used it several times with no problem, although I have used it with gcc (on both windows and linux) and not Visual Studio.

For actual use, the documentation is here .

You can specify how many reserves to reserve with

void resize(size_type n)

      

Regarding your problem with the ID T, I assume you forgot to replace the template argument named T with the actual type. If you can't figure it out, maybe paste in a piece of code on how you are using 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;
}

      

You can of course use std :: string instead of char * if you like:

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

      

+1


source


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

added additional directory for the project where SGI STL.

Could you expand a little? There are many places where you can add directories in the visual studio project settings. that is, adding additional include header paths, additional library paths, etc. Where did you add your catalog?

0


source


This sounds reasonable. What is the structure of your STL directory? Did you get all SGI STL files from your site or just one? You may be missing a dependency file that is causing the error you are seeing.

0


source


I downloaded a zipped version of this library, this zip file only has header files. There is another option in Linker, it calls additional dependencies, but there are only * .lib files there. The command line for my settings looks like this:

/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 use it anymore ...

0


source


Yes you will only find the header files that are listed on the SGI STL website. As you noticed the links are linked for the .lib files, so there is no need to add anything.

Are you compiling the example posted by Dan is still correct? You may need to specify include headers using quotes rather than parentheses. So use ...

#include "hash_map"

      

instead...

#include <hash_map>

      

This could be a problem with the way the files are searched by the compiler. As an additional query, which version of Visual Studio are you using?

0


source


As noted in a thread I noticed on the discussion forum on this issue, the SGI STL implementation doesn't seem to have been updated for a very long time. On the download page, it mentions June 8, 2000 as the last time it was updated. I suspect the SGI STL implementation to work in VS 2005/2008 is more of a problem than it is worth.

I would suggest checking out some STL alternatives ...

Both are updated regularly.

0


source







All Articles