gpt4 book ai didi

c++ - std::vector 作为 std::set 和 std::unordered_set 中的键

转载 作者:行者123 更新时间:2023-11-30 05:40:38 25 4
gpt4 key购买 nike

我正在编写一个程序来评估棋盘游戏(即 othello)中的大量位置。我的董事会代表是 std::vector .由于同一位置在处理过程中可能会出现更多次,因此我使用 std::set<std::vector>存储检查位置。

就性能而言,我不知道使用 std::set 是否更好(因为 std::vector 实现了所有需要的运算符,所以 本地 有效)或 std::unordered_set具有良好的散列 功能(即 boost::hash_range(...) )。

或者还有其他好的解决方案可以实现相同的目标吗? (可能是不同的板表示法 [bitboards for sure when available] 或不同的数据结构?)

编辑 ****************************************** 编辑

这是获取板的伪代码:

enqueue initial board
while queue not empty:
dequeue a board
if board is already examined: //std::set search
continue
put board in examined boards
if board is solved:
print solution
else:
for each possible board that can arise out of this one:
add board to end of queue

最佳答案

Why on earth would anyone use set instead of unordered_set?

what is the difference between set and unordered_set in C++?

基本上:除非您关心值的顺序,否则您应该使用 unordered_set。

但至于所有其他性能问题:如有疑问 --> 开始测量。实现“less”和“hash”,然后用这两个类尝试它并检查哪个表现更好(注意:在这种情况下你没有几乎相同的 API。所以切换类应该不会花你很长时间用于测试)

关于c++ - std::vector 作为 std::set 和 std::unordered_set 中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31543112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com