Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed May 16, 2023
1 parent a029000 commit 42d39ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
25 changes: 19 additions & 6 deletions src/include/processor/operator/recursive_extend/path_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@
namespace kuzu {
namespace processor {

/*
* PathScanner Design
*
* RecursiveJoin first compute frontier from src to dst using BFS.
*
* PathScanner then scans frontiers from dst to src using DFS. We use stack-based DFS to track
* prefix. We scan from dst to src because semi mask might be available and we only need to scan a
* subset of all dst nodes.
*
* Since variable-length join requires union of path with different length (e.g. *2..3), PathScanner
* scans length by length, i.e. we first scan all length 2 path from second frontier, then scan all
* length 3 path from third frontier.
*/

// FixedSizePathScanner scans all paths of a fixed length.
struct FixedLengthPathScanner {
using nbrs_t = std::vector<common::offset_t>*;

// FixedLengthPathScanner scans from bfsMorsel frontiers and semi mask.
const BaseBFSMorsel& bfsMorsel;
// Number of extension performed during recursive join
size_t depth;
// Current path.
size_t numRels;
std::vector<common::offset_t> path;

// DFS states
Expand All @@ -23,9 +36,9 @@ struct FixedLengthPathScanner {

size_t lastFrontierCursor;

FixedLengthPathScanner(const BaseBFSMorsel& bfsMorsel, size_t depth)
: bfsMorsel{bfsMorsel}, depth{depth} {
path.resize(depth + 1);
FixedLengthPathScanner(const BaseBFSMorsel& bfsMorsel, size_t numRels)
: bfsMorsel{bfsMorsel}, numRels{numRels} {
path.resize(numRels + 1);
resetState();
}

Expand Down
20 changes: 12 additions & 8 deletions src/processor/operator/recursive_extend/path_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ size_t FixedLengthPathScanner::scanPaths(common::table_id_t tableID,
common::ValueVector* pathOffsetVector, common::ValueVector* pathDataVector,
common::ValueVector* dstNodeIDVector, common::sel_t& offsetVectorPos,
common::sel_t& dataVectorPos) {
if (depth >= bfsMorsel.frontiers.size()) {
if (numRels >= bfsMorsel.frontiers.size()) {
// BFS terminate before current depth. No need to scan.
return 0;
}
auto offsetVectorPosBeforeScanning = offsetVectorPos;
auto frontier = bfsMorsel.frontiers[depth].get();
auto lastFrontier = bfsMorsel.frontiers[numRels].get();
while (offsetVectorPos < common::DEFAULT_VECTOR_CAPACITY) {
if (!continueDfs()) {
if (lastFrontierCursor == frontier->nodeOffsets.size()) {
// All paths from current dst have been scanned. Fetch next dst.
if (lastFrontierCursor == lastFrontier->nodeOffsets.size()) {
// All nodes from last frontier have been scanned.
break;
}
auto currentDstOffset = frontier->nodeOffsets[lastFrontierCursor++];
auto currentDstOffset = lastFrontier->nodeOffsets[lastFrontierCursor++];
// Skip nodes that is not in semi mask.
if (!bfsMorsel.isAllDstTarget() &&
!bfsMorsel.targetDstNodeOffsets.contains(currentDstOffset)) {
continue;
}
initDfs(currentDstOffset, depth);
// Prepare dfs stack.
initDfs(currentDstOffset, numRels);
}
writePathToVector(tableID, pathOffsetVector, pathDataVector, dstNodeIDVector,
offsetVectorPos, dataVectorPos);
Expand All @@ -37,16 +40,17 @@ bool FixedLengthPathScanner::continueDfs() {
while (!nbrsStack.empty()) {
auto& cursor = cursorStack.top();
cursor++;
if (cursor < nbrsStack.top()->size()) {
if (cursor < nbrsStack.top()->size()) { // Found a new nbr
auto offset = nbrsStack.top()->at(cursor);
path[level] = offset;
if (level == 0) {
if (level == 0) { // Found a new nbr at level 0. Found a new path.
return true;
}
// Push new stack.
cursorStack.push(-1);
nbrsStack.push(&bfsMorsel.frontiers[level]->bwdEdges.at(offset));
level--;
} else {
} else { // Failed to find a nbr. Pop stack.
cursorStack.pop();
nbrsStack.pop();
level++;
Expand Down

0 comments on commit 42d39ef

Please sign in to comment.