c++ - STL::sets的STL::map的效率

标签 c++ boost stl boost-icl

我相信我想使用 boost::icl::interval_map 来解决问题(描述 here ,如果 interval_maps 最终有效,我将发布完整的答案。)

我想使用 interval_map<unsigned long long, set<foo*>> ,但是 boost::icl 的文档提到存在潜在的效率问题(低于 from )。

We are introducing interval_maps using an interval map of sets of strings, because of it's didactic advantages. The party example is used to give an immediate access to the basic ideas of interval maps and aggregate on overlap. For real world applications, an interval_map of sets is not necessarily recommended. It has the same efficiency problems as a std::map of std::sets. There is a big realm though of using interval_maps with numerical and other efficient data types for the associated values.

std::map of std::sets 的效率问题是什么? 以及我怎样才能避免它们?

最佳答案

两者都是 std::map<K, V>std::set<V>是由指针链接的基于节点的容器。遍历它们具有很好的复杂性保证(即,每个单独的操作至多为 O(log n)),但您实际上需要相当大的容器来比较复杂性,例如,与 std::vector<std::pair<K, V>> 相比。特别是当 KV是基本类型。基于节点的容器的主要性能问题是它们或多或少地随机分布在内存中,而现代 CPU 喜欢访问以某种形式聚集的数据。

当然,像往常一样,您需要在相当真实的数据集上测量不同实现之间获得的时间,以确定哪种数据结构产生最佳性能。

关于c++ - STL::sets的STL::map的效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18581957/

相关文章:

c++ - 使用 vector 中的值(特征)来计算 opencv 的余弦相似度

c++ - C++中的数组初始化

c++ - Qt VS 工具 : error reading VS project settings

c++ - 使用 C++/boost::asio/libcurl 的简单代理 - 无法下载图像

c++ - property_tree : cannot set a default property value?

c++ - 使用具有继承类的容器

c++ - 与自身双重比较

python - 在 boost.python 中使用它时不能在我的抽象类中使用纯虚函数

c++ - 无法访问堆上的 vector

c++ - STL 文档