Skip to content

Commit a0af98c

Browse files
committed
[breadthFirstSearch] Modified function to return empty result when source node is not present in graph
1 parent 2612933 commit a0af98c

3 files changed

Lines changed: 3 additions & 5 deletions

File tree

doc/queries/doc-pgr_breadthFirstSearch.queries

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ SELECT * FROM pgr_breadthFirstSearch(
5858
);
5959
seq | depth | start_vid | node | edge | cost | agg_cost
6060
-----+-------+-----------+------+------+------+----------
61-
1 | 0 | 0 | 0 | -1 | 0 | 0
62-
(1 row)
61+
(0 rows)
6362

6463
ROLLBACK;
6564
ROLLBACK

include/breadthFirstSearch/pgr_breadthFirstSearch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Pgr_breadthFirstSearch
5757
for (auto source : start_vertex)
5858
{
5959
std::vector<E> visited_order;
60-
results.push_back({source, 0, source, -1, 0.0, 0.0});
6160
if (graph.has_vertex(source))
6261
{
62+
results.push_back({source, 0, source, -1, 0.0, 0.0});
6363
boost::breadth_first_search(graph.graph,
6464
graph.get_V(source),
6565
visitor(bfs_visitor(visited_order)));

test/breadthFirstSearch/doc-pgr_breadthFirstSearch.result

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ SELECT * FROM pgr_breadthFirstSearch(
5858
);
5959
seq | depth | start_vid | node | edge | cost | agg_cost
6060
-----+-------+-----------+------+------+------+----------
61-
1 | 0 | 0 | 0 | -1 | 0 | 0
62-
(1 row)
61+
(0 rows)
6362

6463
ROLLBACK;
6564
ROLLBACK

0 commit comments

Comments
 (0)