Skip to content

Commit

Permalink
Fix the bug of not being able to find longer paths
Browse files Browse the repository at this point in the history
  • Loading branch information
SiberiaWolfP committed Feb 13, 2024
1 parent 1f21138 commit cb66073
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ duckdb_unittest_tempdir/
testext
test/python/__pycache__/
.Rhistory
.vscode
35 changes: 30 additions & 5 deletions duckpgq/src/duckpgq/functions/scalar/iterativelength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ static bool IterativeLength(int64_t v_size, int64_t *v, vector<int64_t> &e,
}
}
for (auto i = 0; i < v_size; i++) {
next[i] = next[i] & ~seen[i];
// next[i] = next[i] & ~seen[i];
seen[i] = seen[i] | next[i];

// change |= next[i].any();
}

vector<std::bitset<LANE_LIMIT>> next_next = vector<std::bitset<LANE_LIMIT>>(v_size, 0);
// If a vertex in next is a successor of other vertices in next, set it as unvisited
for (auto i = 0; i < v_size; i++) {
if (next[i].any()) {
for (auto offset = v[i]; offset < v[i + 1]; offset++) {
auto n = e[offset];
next_next[n] = next_next[n] | next[i];
}
}
}
for (auto i = 0; i < v_size; i++) {
next[i] = next[i] & ~next_next[i];
}

for (auto i = 0; i < v_size; i++) {
change |= next[i].any();
}

return change;
}

Expand Down Expand Up @@ -136,10 +156,12 @@ static void IterativeLengthFunction(DataChunk &args, ExpressionState &state,

// make passes while a lane is still active
for (int64_t iter = 1; active; iter++) {
if (!IterativeLength(v_size, v, e, seen, (iter & 1) ? visit1 : visit2,
(iter & 1) ? visit2 : visit1)) {
break;
}
// if (!IterativeLength(v_size, v, e, seen, (iter & 1) ? visit1 : visit2,
// (iter & 1) ? visit2 : visit1)) {
// break;
// }
bool stop = !IterativeLength(v_size, v, e, seen, (iter & 1) ? visit1 : visit2,
(iter & 1) ? visit2 : visit1);
// detect lanes that finished
for (int64_t lane = 0; lane < LANE_LIMIT; lane++) {
int64_t search_num = lane_to_num[lane];
Expand Down Expand Up @@ -169,6 +191,9 @@ static void IterativeLengthFunction(DataChunk &args, ExpressionState &state,
}
}
}
if (stop) {
break;
}
}

// no changes anymore: any still active searches have no path
Expand Down

0 comments on commit cb66073

Please sign in to comment.