MCPcopy Create free account
hub / github.com/dhbloo/rapfi / copyDatabaseBranch

Function copyDatabaseBranch

Rapfi/database/dbutils.cpp:62–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void copyDatabaseBranch(DBStorage &dbSrc,
63 DBStorage &dbDst,
64 Board &board,
65 Rule rule,
66 int threadId,
67 int ply)
68{
69 // Find all potential children of this board position
70 std::vector<Pos> toCopyPos;
71 toCopyPos.reserve(board.movesLeft());
72 FOR_EVERY_EMPTY_POS(&board, pos)
73 {
74 toCopyPos.push_back(pos);
75 }
76
77 // Do permutation based on thread id
78 if (threadId > 0) {
79 for (size_t i = 0; i < toCopyPos.size(); i += (threadId + 1) / 2) {
80 size_t swapIndex = (i * (threadId + 1)) % toCopyPos.size();
81 std::swap(toCopyPos[i], toCopyPos[swapIndex]);
82 }
83 }
84
85 // Copy all children
86 DBKey key;
87 DBRecord record, tempRecord;
88 for (auto pos : toCopyPos) {
89 board.move(rule, pos);
90
91 key = constructDBKey(board, rule);
92
93 if (dbSrc.get(key, record, RECORD_MASK_ALL)
94 && !dbDst.get(key, tempRecord, RECORD_MASK_NONE)) {
95 copyDatabaseBranch(dbSrc, dbDst, board, rule, threadId, ply + 1);
96 dbDst.set(key, record, RECORD_MASK_ALL);
97 }
98
99 board.undo(rule);
100 }
101}
102
103} // namespace
104

Callers 1

splitDatabaseFunction · 0.85

Calls 11

constructDBKeyFunction · 0.85
movesLeftMethod · 0.80
setMethod · 0.80
FOR_EVERY_EMPTY_POSFunction · 0.50
swapFunction · 0.50
reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
moveMethod · 0.45
getMethod · 0.45
undoMethod · 0.45

Tested by

no test coverage detected