Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed May 14, 2023
1 parent ba5aa84 commit ae70e7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/include/processor/operator/recursive_extend/path_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
namespace kuzu {
namespace processor {

// FixedSizePathScanner scans all path for a fixed length.
struct FixedSizePathScanner {
const BaseBFSMorsel& bfsMorsel;
// Number of extension performed during recursive join
size_t depth;

// Current path. TODO(Xiyang): we can remove this and directly read from cursor and nbrs.
std::vector<common::offset_t> path;

// States
std::vector<size_t> cursorPerDepth;
std::vector<std::vector<common::offset_t>*> nbrsPerDepth;
common::offset_t currentDstOffset;
Expand All @@ -32,17 +36,10 @@ struct FixedSizePathScanner {
private:
bool dfs(size_t currentDepth);

void initDfs(common::offset_t offset, size_t currentDepth) {
path[currentDepth] = offset;
if (currentDepth == 0) {
return;
}
nbrsPerDepth[currentDepth - 1] = &bfsMorsel.frontiers[currentDepth]->bwdEdges.at(offset);
cursorPerDepth[currentDepth - 1] = 0;
initDfs(nbrsPerDepth[currentDepth - 1]->at(0), currentDepth - 1);
}
void initDfs(common::offset_t offset, size_t currentDepth);
};

// PathScanner scans path whose length falls into [lowerBound, upperBound].
struct PathScanner {
size_t lowerBound;
size_t upperBound;
Expand Down
16 changes: 15 additions & 1 deletion src/processor/operator/recursive_extend/path_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ namespace kuzu {
namespace processor {

bool FixedSizePathScanner::getNext() {
if (depth >= bfsMorsel.frontiers.size()) { // BFS terminate before current depth
if (depth >= bfsMorsel.frontiers.size()) {
// BFS terminate before current depth. No need to scan.
return false;
}
auto frontier = bfsMorsel.frontiers[depth].get();
auto& cursor = cursorPerDepth[depth];
if (dfs(0)) {
// Find a path for currentDstOffset;
return true;
}
while (cursor < frontier->nodeOffsets.size()) {
Expand All @@ -19,6 +21,8 @@ bool FixedSizePathScanner::getNext() {
!bfsMorsel.targetDstNodeOffsets.contains(currentDstOffset)) {
continue;
}
// Init nbrs and first path. We guarantee (from BFS computation) to have at least one path
// that reaches currentDstOffset.
initDfs(currentDstOffset, depth);
return true;
}
Expand Down Expand Up @@ -49,6 +53,16 @@ bool FixedSizePathScanner::dfs(size_t currentDepth) {
}
}

void FixedSizePathScanner::initDfs(common::offset_t offset, size_t currentDepth) {
path[currentDepth] = offset;
if (currentDepth == 0) {
return;
}
nbrsPerDepth[currentDepth - 1] = &bfsMorsel.frontiers[currentDepth]->bwdEdges.at(offset);
cursorPerDepth[currentDepth - 1] = 0;
initDfs(nbrsPerDepth[currentDepth - 1]->at(0), currentDepth - 1);
}

bool PathScanner::getNext() {
while (cursor < scanners.size()) {
if (scanners[cursor]->getNext()) {
Expand Down

0 comments on commit ae70e7f

Please sign in to comment.