C ++数据结构与lookuptime O(1),像java的hashmap在stl?

编程入门 行业动态 更新时间:2024-10-15 22:26:04
本文介绍了C ++数据结构与lookuptime O(1),像java的hashmap在stl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 c ++标准库中有这样一个结构吗?我没有访问任何其他,所以在tr1中unordered_map不能使用(和boost等)。

我拥有的是大量的自定义类元素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?

本文发布于:2023-11-30 02:07:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据结构   lookuptime   java   hashmap   stl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!