C ++数据结构与lookuptime O(1),像java的hashmap在stl? [英] C++ data structure with lookuptime O(1), like java's hashmap in stl?

查看:164
本文介绍了C ++数据结构与lookuptime O(1),像java的hashmap在stl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++标准库中有这样的结构吗?我没有访问其他任何东西,所以unordered_map在tr1不能使用(和boost等)。

Is there such a structure in c++ standard library? I don't have access to anything else so unordered_map in tr1 cant be used (and boost etc).

我有一个大量的自定义类元素100000+我需要存储,并访问他们非常快的O(1)在饮料。我不能使用数组/向量,因为元素将被随机存储,我不知道元素的位置。

What I have is a large number of custom class elements 100000+ which I need to store, and access them very fast O(1) on everage. I can't use arrays/vectors as the elements will be stored randomly and I don't know the position of the element.

是我唯一的替代实现自己hashmap实现只有c ++标准库可用?

Is my only alternative to implements an own hashmap implementation with only the c++ standard library available?

推荐答案

问题是O(1)查找不是标准。我不确定增强有什么,但一些STL实现(如sgi)has hash_map。这是你需要的。

The problem is that the O(1) lookup is not standard. I am unsure about what boost has, but some STL implementations (like sgi) have hash_map. That's what you need.

这里是文档

只需尝试:

#include <hash_map>

请记住,如果这个工作,它不可移植...但也许现在,以后您可以找到解决方法。

Keep in mind if this works, it is not portable... but maybe for now that's ok, and later you can find workarounds.

这篇关于C ++数据结构与lookuptime O(1),像java的hashmap在stl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆