Skip to content

Commit 09e5e2d

Browse files
committed
[depthFirstSearch] Added directed boolean parameter
1 parent cb0a9a6 commit 09e5e2d

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

include/drivers/depthFirstSearch/depthFirstSearch_driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void do_pgr_depthFirstSearch(
5353
size_t size_rootsArr,
5454

5555
int64_t max_depth,
56+
bool directed,
5657

5758
pgr_mst_rt **return_tuples,
5859
size_t *return_count,

sql/depthFirstSearch/_depthFirstSearch.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CREATE OR REPLACE FUNCTION _pgr_depthFirstSearch(
3737
edges_sql TEXT,
3838
root_vids ANYARRAY,
3939
max_depth BIGINT,
40+
directed BOOLEAN,
4041

4142
OUT seq BIGINT,
4243
OUT depth BIGINT,
@@ -53,6 +54,6 @@ LANGUAGE C VOLATILE STRICT;
5354
-- COMMENTS
5455

5556

56-
COMMENT ON FUNCTION _pgr_depthFirstSearch(TEXT, ANYARRAY, BIGINT)
57+
COMMENT ON FUNCTION _pgr_depthFirstSearch(TEXT, ANYARRAY, BIGINT, BOOLEAN)
5758
IS 'pgRouting internal function';
5859

sql/depthFirstSearch/depthFirstSearch.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CREATE OR REPLACE FUNCTION pgr_depthFirstSearch(
3333
BIGINT, -- root_vid (required)
3434

3535
max_depth BIGINT DEFAULT 9223372036854775807,
36+
directed BOOLEAN DEFAULT true,
3637

3738
OUT seq BIGINT,
3839
OUT depth BIGINT,
@@ -52,7 +53,7 @@ BEGIN
5253

5354
RETURN QUERY
5455
SELECT *
55-
FROM _pgr_depthFirstSearch(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], $3);
56+
FROM _pgr_depthFirstSearch(_pgr_get_statement($1), ARRAY[$2]::BIGINT[], max_depth, directed);
5657
END;
5758
$BODY$
5859
LANGUAGE plpgsql VOLATILE STRICT;
@@ -64,6 +65,7 @@ CREATE OR REPLACE FUNCTION pgr_depthFirstSearch(
6465
ANYARRAY, -- root_vids (required)
6566

6667
max_depth BIGINT DEFAULT 9223372036854775807,
68+
directed BOOLEAN DEFAULT true,
6769

6870
OUT seq BIGINT,
6971
OUT depth BIGINT,
@@ -83,7 +85,7 @@ BEGIN
8385

8486
RETURN QUERY
8587
SELECT *
86-
FROM _pgr_depthFirstSearch(_pgr_get_statement($1), $2, $3);
88+
FROM _pgr_depthFirstSearch(_pgr_get_statement($1), $2, max_depth, directed);
8789
END;
8890
$BODY$
8991
LANGUAGE plpgsql VOLATILE STRICT;
@@ -92,26 +94,26 @@ LANGUAGE plpgsql VOLATILE STRICT;
9294
-- COMMENTS
9395

9496

95-
COMMENT ON FUNCTION pgr_depthFirstSearch(TEXT, BIGINT, BIGINT)
97+
COMMENT ON FUNCTION pgr_depthFirstSearch(TEXT, BIGINT, BIGINT, BOOLEAN)
9698
IS 'pgr_depthFirstSearch(Single Vertex)
97-
- Undirected graph
9899
- Parameters:
99100
- Edges SQL with columns: id, source, target, cost [,reverse_cost]
100101
- From root vertex identifier
101102
- Optional parameters
102103
- max_depth := 9223372036854775807
104+
- directed := true
103105
- Documentation:
104106
- ${PGROUTING_DOC_LINK}/pgr_depthFirstSearch.html
105107
';
106108

107-
COMMENT ON FUNCTION pgr_depthFirstSearch(TEXT, ANYARRAY, BIGINT)
109+
COMMENT ON FUNCTION pgr_depthFirstSearch(TEXT, ANYARRAY, BIGINT, BOOLEAN)
108110
IS 'pgr_depthFirstSearch(Multiple Vertices)
109-
- Undirected graph
110111
- Parameters:
111112
- Edges SQL with columns: id, source, target, cost [,reverse_cost]
112113
- From ARRAY[root vertices identifiers]
113114
- Optional parameters
114115
- max_depth := 9223372036854775807
116+
- directed := true
115117
- Documentation:
116118
- ${PGROUTING_DOC_LINK}/pgr_depthFirstSearch.html
117119
';

sql/sigs/pgrouting--3.0.0.sig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ _pgr_dagshortestpath(text,anyarray,anyarray,boolean,boolean)
8080
pgr_dagshortestpath(text,anyarray,bigint)
8181
pgr_dagshortestpath(text,bigint,anyarray)
8282
pgr_dagshortestpath(text,bigint,bigint)
83-
_pgr_depthfirstsearch(text,anyarray,bigint)
84-
pgr_depthfirstsearch(text,anyarray,bigint)
85-
pgr_depthfirstsearch(text,bigint,bigint)
83+
_pgr_depthfirstsearch(text,anyarray,bigint,boolean)
84+
pgr_depthfirstsearch(text,anyarray,bigint,boolean)
85+
pgr_depthfirstsearch(text,bigint,bigint,boolean)
8686
pgr_dijkstracostmatrix(text,anyarray,boolean)
8787
pgr_dijkstracost(text,anyarray,anyarray,boolean)
8888
pgr_dijkstracost(text,anyarray,bigint,boolean)

src/depthFirstSearch/depthFirstSearch.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ process(
5050
char* edges_sql,
5151
ArrayType *roots,
5252
int64_t max_depth,
53+
bool directed,
5354

5455
pgr_mst_rt **result_tuples,
5556
size_t *result_count) {
@@ -75,22 +76,23 @@ process(
7576

7677
pgr_get_edges(edges_sql, &edges, &total_edges);
7778

78-
79+
PGR_DBG("Starting processing");
7980
clock_t start_t = clock();
8081
do_pgr_depthFirstSearch(
8182
edges, total_edges,
8283
rootsArr, size_rootsArr,
8384

8485
max_depth,
86+
directed,
8587

8688
result_tuples,
8789
result_count,
8890
&log_msg,
8991
&notice_msg,
9092
&err_msg);
9193

92-
9394
time_msg("processing pgr_depthFirstSearch", start_t, clock());
95+
PGR_DBG("Returning %ld tuples", *result_count);
9496

9597
if (err_msg) {
9698
if (*result_tuples) pfree(*result_tuples);
@@ -111,22 +113,38 @@ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) {
111113
FuncCallContext *funcctx;
112114
TupleDesc tuple_desc;
113115

116+
/**********************************************************************/
114117
pgr_mst_rt *result_tuples = NULL;
115118
size_t result_count = 0;
119+
/**********************************************************************/
116120

117121
if (SRF_IS_FIRSTCALL()) {
118122
MemoryContext oldcontext;
119123
funcctx = SRF_FIRSTCALL_INIT();
120124
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
121125

122-
/* Edge sql, tree roots, max_depth */
126+
/**********************************************************************/
127+
/*
128+
pgr_depthFirstSearch(
129+
edges_sql TEXT,
130+
root_vids ANYARRAY,
131+
max_depth BIGINT DEFAULT 9223372036854775807,
132+
directed BOOLEAN DEFAULT true
133+
);
134+
*/
135+
/**********************************************************************/
136+
137+
PGR_DBG("Calling process");
123138
process(
124139
text_to_cstring(PG_GETARG_TEXT_P(0)),
125140
PG_GETARG_ARRAYTYPE_P(1),
126141
PG_GETARG_INT64(2),
142+
PG_GETARG_BOOL(3),
127143
&result_tuples,
128144
&result_count);
129145

146+
/**********************************************************************/
147+
130148

131149
#if PGSQL_VERSION > 95
132150
funcctx->max_calls = result_count;
@@ -156,6 +174,18 @@ PGDLLEXPORT Datum _pgr_depthfirstsearch(PG_FUNCTION_ARGS) {
156174
Datum *values;
157175
bool* nulls;
158176

177+
/**********************************************************************/
178+
/*
179+
OUT seq BIGINT,
180+
OUT depth BIGINT,
181+
OUT start_vid BIGINT,
182+
OUT node BIGINT,
183+
OUT edge BIGINT,
184+
OUT cost FLOAT,
185+
OUT agg_cost FLOAT
186+
*/
187+
/**********************************************************************/
188+
159189
size_t num = 7;
160190
values = palloc(num * sizeof(Datum));
161191
nulls = palloc(num * sizeof(bool));

src/depthFirstSearch/depthFirstSearch_driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4040
#include "spanningTree/details.hpp"
4141

4242

43+
// TODO(krashish8): Use the directed parameter below.
4344
void
4445
do_pgr_depthFirstSearch(
4546
pgr_edge_t *data_edges,
@@ -49,6 +50,7 @@ do_pgr_depthFirstSearch(
4950
size_t size_rootsArr,
5051

5152
int64_t max_depth,
53+
bool directed,
5254

5355
pgr_mst_rt **return_tuples,
5456
size_t *return_count,

0 commit comments

Comments
 (0)