Std::vector作为Std::set和Std::unordered_set中的键
std::vector as key in std::set and std::unordered_set
我正在编写一个程序,计算棋盘游戏(即奥赛罗)中的大量位置。我的董事会代表是一个std::vector
。由于同一个位置在处理过程中可以出现多次,所以我使用std::set<std::vector>
来存储检查过的位置。
在性能方面,我不知道是否更可取使用std::set
(工作原生,因为std::vector
实现所需的所有运算符)或std::unordered_set
具有良好的哈希功能(即boost::hash_range(...)
)。
是否有其他好的解决方案来实现相同的目标?(可能是不同的板表示[位板确定可用时]或不同的数据结构?)
编辑 ************************************** 编辑
这是获取板的伪代码:
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
参见
为什么会有人用set而不是unordered_set呢?
c++中set和unordered_set的区别是什么?基本上:除非你关心值的顺序,否则你可能应该使用unordered_set。
但对于所有其他性能问题:当有疑问时->开始测量。同时实现"less"answers"hash",然后用两个类尝试并检查哪个性能更好(注意:在这种情况下,你没有几乎相同的API。所以你不应该花很长时间来切换类进行测试)
相关文章:
- 在声明中合并两个常量"std::set"(不是在运行时)
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将 std::set 与基于键的比较器一起使用
- 修改"std::set"中用户定义类型的值
- 如何在构造函数参数中初始化"std::set"?
- 如何使用 lower_bound/upper_bound 从 std::set 获取索引号?
- 如何在 C++ 中转发声明 std::set?
- 重构使用动态强制转换的 std::set 的比较运算符
- 为什么 std::set.erase(first, last) 会影响从中获取 (first, last) 的容器?
- std::set 是否将对象连续存储在内存中?
- 是否有一个 std::set 函数来确定不超过数字 x 的最大元素?
- 有什么理由不扩展 std::set 以添加下标运算符吗?
- 我从 std::set 得到const_iterator而不是迭代器
- 为什么 std:set(带有单个冒号)可以编译?
- 遍历 std::set 中包含的所有三重不同值?
- 插入 std::set 作为 std::map 的键
- 如何在 c++ 中使用默认值将 std::set 转换为 std::map
- 错误:'class std::unique_ptr<std::set<long unsigned int> >'没有名为 'size' 的成员
- 如何从 std::set 绘制 n 个元素的样本
- 为什么 std::set 容器使用的内存比其数据大小多得多?