我拥有的是大量的自定义类元素100000+我需要存储,并在O(1)上进行快速访问。我不能使用数组/向量,因为元素将被随机存储,我不知道元素的位置。
我唯一的替代方法是实现自己的hashmap实现只有c ++标准库可用?
解决方案问题是O(1)查找不是标准的。我不确定boost有什么,但一些STL实现(如sgi)有hash_map。这就是你需要的。
这里是文档。
只是尝试一下:
#include< hash_map>请记住,如果这样工作,它不是便携式的...但是现在可以,之后您可以找到解决方法。
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).
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.
Is my only alternative to implements an own hashmap implementation with only the c++ standard library available?
解决方案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.
Here is the documentation.
Just try out:
#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?
发布评论