c++ - 为什么 std::set 在 std::vector 上优于 std::priority_queue 在 std::deque 上优于 std::priority_queue?
问题描述
在实现 A* 时,我尝试了三种类型的容器:std::set
、std::priority_queue
onstd::vector
和std::priority_queue
on std::deque
。
我使用的唯一操作是push(e)
、pop()
和top()
。
push(e)
on仅std::set
使用实现insert(e)
。pop
是m_data.erase(m_data.begin())
,并且top()
是*m_data.begin()
。
std::priority_queue
对于给定的操作,没有对onstd::vector
和std::priority_queue
on进行额外的实现std::deque
。
在其他一切不变的情况下,std::set
工作速度比其他两个选项快两倍左右。
为什么会这样?如果总是如此,为什么要std::priority_queue
在效率方面使用?
PS 所有这些的复杂性push(e)
是logn
(n
容器中元素的数量在哪里)。pop()
for的给定实现std::set
是 amortized ,如此处const
所示,对于其他两个选项,它是(其中是比较次数),如此处所示。适合所有人。logn
n
top
const
PPS 我不太明白这里the number of comparisons
是什么意思。是堆的深度吗?
可以在此处找到有关实施的详细信息。
解决方案
推荐阅读
- c++ - 必须将 C++ 中的十六进制文件加载到缓冲区中吗?
- javascript - 如何根据对象属性对对象数组进行分组?
- sql - Microsoft SSMS 中的运行总计
- python - pyarrow.lib.ArrowNotImplementedError:尚不支持从 Parquet 文件中读取结构列表:paygw_etp_typs: list
我正在使用 Great Expectations 来测试 ETL 管道中的数据。我拥有的数据文件是 Parquet 格式并且确实有一些数组,当我尝试创建新套件或尝试使用 pyarrow/fastparquet 转换为可读格式时,我遇到以下错误:
- postgresql - 我的 docker postgres 数据库容器的连接数从 11 开始?
- git - 如何使用 gitbash 命令删除 github 中的 repo?
- wordpress - Themeforest 的高级 wordpress 主题开发
- flutter - 在 Flutter 输入中将值转换为数字格式?
- java - 使用两个队列的级别顺序遍历二叉树
- xamarin.forms - 当 UICollectionViewFlowLayout.PrepareLayout() 时 Xamarin iOS 应用程序在监视器中暂停