[英]std::set with unconsistent operator<
I'm writing a C++ algorithm to solve a board game. 我正在编写一种C ++算法来解决棋盘游戏。 The solution is based on the following:
该解决方案基于以下内容:
enqueue initial board
while queue not empty:
dequeue a board
if board is solved:
print solution
else:
for each possible board that can arise out of this one:
add board to end of queue
Since I don't want to examine the same board more than one time I use std::set<Board>
to keep track of examined boards. 由于我不想多次检查同一块板,因此我使用
std::set<Board>
来跟踪检查过的板。
In Board
class bool operator<(const Board& rhs) const
is defined to make std::set
work properly. 在
Board
类中,定义bool operator<(const Board& rhs) const
以使std::set
正常工作。
So what happens in my std::set
if my comparison function doesn't ensure an order in board instances? 那么,如果我的比较功能不能确保板实例中的顺序,那么在
std::set
会发生什么?
As example: 例如:
a = Board()
b = Board()
c = Board()
a > b returns true
b > c returns true
a > c returns false
Is it possible that std::set
, since it's based on Red-Black Tree , inserts the same Board more than once? 由于
std::set
基于Red-Black Tree ,是否有可能多次插入同一块Board?
If the comparator doesn't work properly, the structure won't work properly. 如果比较器无法正常工作,则该结构将无法正常工作。 It might report that items are missing.
它可能会报告缺少项目。 It might fail to insert something.
可能无法插入某些内容。 It could crash quickly, or it could appear to work for all your test cases and then crash on the customer's machine.
它可能很快崩溃,或者似乎可以用于所有测试用例,然后在客户的计算机上崩溃。
All bets are off. 所有赌注都关闭了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.