如何使用SGI STL hash_map?

发布于 2024-07-09 23:34:42 字数 323 浏览 7 评论 0原文

我正在尝试使用从他们的网站下载的 SGI STL 实现。 我想使用哈希图,因为我必须存储大约 5.000.000 条记录,但它应该很好:我需要能够非常快速地访问它。 我尝试过 stedext::hash_map,但速度非常慢,因为我无法设置初始大小。 顺便问一下,可以这样做吗? 如果我将附加路径添加到 MS Visual Studio,我什至无法从 SGI 站点编译示例。 我收到一条错误消息:

error C2061: syntax error : identifier 'T'.

还有其他人遇到过此类问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

情深缘浅 2024-07-16 23:34:42

我承认我还没有亲自尝试过,但 VS2008 应该支持 TR1,其中包含:

#include <tr1/unordered_map>

它位于“功能包”版本中。
http://www.microsoft.com/downloads/details.aspx microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&displaylang=en

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&displaylang=en

淡墨 2024-07-16 23:34:42

我已经使用它很多次了,没有出现任何问题,尽管我将它与 gcc(在 Windows 和 Linux 上)而不是 Visual Studio 一起使用。

对于实际使用,文档位于此处

您可以使用指定要保留的存储桶数量。

void resize(size_type n)

关于您的标识符 T 问题,我假设您忘记将名为 T 的模板参数替换为实际类型。 如果您无法弄清楚,也许可以粘贴一段有关如何使用 hash_map 的代码片段。

文档中的示例:

#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;
}

当然,如果您愿意,您可以使用 std::string 而不是 char* :

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

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;
多像笑话 2024-07-16 23:34:42

当您尝试构建/编译项目时是否出现任何其他错误消息?
你提到你...

添加了一个附加目录
SGI STL所在的项目。

你能扩展一下吗? 您可以在 Visual Studio 项目设置中的许多位置添加目录。 即添加额外的包含头路径、额外的库路径等。您在哪里添加目录?

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?

野鹿林 2024-07-16 23:34:42

听起来很有道理。 你的STL目录的结构是什么? 您是从他们的网站获得所有 SGI STL 文件还是仅获得一个? 可能是您缺少依赖文件,从而导致您看到错误。

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.

想你的星星会说话 2024-07-16 23:34:42

我已经下载了这个库的压缩版本,该压缩文件中只有头文件。 Linker下还有一个选项,叫做附加依赖项,但那里只有*.lib文件。
我的设置的命令行看起来:

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

我不知道它是否更有用......

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....

心在旅行 2024-07-16 23:34:42

是的,您只能找到 SGI STL 网站上标明的头文件。 正如您所注意到的,链接依赖项仅适用于 .lib 文件,因此不必费心在其中添加任何内容。

您还在编译 Dan 发布的示例吗? 您可能需要使用引号而不是方括号来指定包含标头。 因此,使用...

#include "hash_map"

而不是...

#include <hash_map>

这可能是编译器如何搜索包含文件的问题。 作为附加询问,您使用的是哪个版本的 Visual Studio?

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?

听风吹 2024-07-16 23:34:42

正如我在一个讨论论坛上注意到的关于这个问题的主题中指出的那样,SGI STL 实现似乎已经很长时间没有更新了。 在下载页面上,它甚至提到最后一次更新时间是 2000 年 6 月 8 日。 我怀疑让 SGI STL 实现在 VS 2005/2008 下工作比它的价值更麻烦。

我建议检查一些 STL 替代品...

两者都会定期更新。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文