Skip to content

Commit 83893ad

Browse files
committed
Update hash function
1 parent 4d3cfb6 commit 83893ad

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cpp/8puzzle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PuzzleState::TILE PuzzleState::g_start[] =
152152

153153
// Three example start states from Bratko's Prolog Programming for Artificial Intelligence
154154

155-
#if 1
155+
#if 0
156156
// ex a - 4 steps
157157
TL_1 ,
158158
TL_3 ,
@@ -267,7 +267,7 @@ PuzzleState::TILE PuzzleState::g_start[] =
267267
TL_7 ,
268268
TL_5 ,
269269

270-
#elif 0
270+
#elif 1
271271

272272
// worst 30
273273
TL_5 ,
@@ -340,12 +340,12 @@ bool PuzzleState::IsSameState( PuzzleState &rhs )
340340
// The 9 tiles positions can be encoded as digits
341341
size_t PuzzleState::Hash()
342342
{
343-
stringstream stream;
343+
std::size_t hash = 0;
344344
for( size_t i = 0; i < (BOARD_HEIGHT * BOARD_WIDTH); i++ )
345345
{
346-
stream << tiles[i];
346+
hash ^= std::hash<int>()(tiles[i]) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
347347
}
348-
return std::hash<std::string>{}(stream.str());
348+
return hash;
349349
}
350350

351351
void PuzzleState::PrintNodeInfo()

0 commit comments

Comments
 (0)