Skip to content

Commit

Permalink
[C] removing unused code
Browse files Browse the repository at this point in the history
* Remove code that reads the SQL query
* Remove include needed for reading SQL query
* Some cleanup
Note: Only C array are read in the C code
  • Loading branch information
cvvergara committed Aug 3, 2023
1 parent 9d51326 commit b83423f
Show file tree
Hide file tree
Showing 58 changed files with 485 additions and 2,880 deletions.
56 changes: 7 additions & 49 deletions src/allpairs/floydWarshall.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/

#include <stdbool.h>

#include "c_common/postgres_connection.h"

#include "c_types/iid_t_rt.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"

#include "c_common/pgdata_getters.h"

#include "drivers/allpairs/floydWarshall_driver.h"

PGDLLEXPORT Datum _pgr_floydwarshall(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(_pgr_floydwarshall);

static
void
process(
void process(
char* edges_sql,
bool directed,
IID_t_rt **result_tuples,
Expand All @@ -55,26 +51,9 @@ process(
char* notice_msg = NULL;
char* err_msg = NULL;

PGR_DBG("Load data");
Edge_t *edges = NULL;
size_t total_tuples = 0;
pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg);
throw_error(err_msg, edges_sql);

if (total_tuples == 0) {
PGR_DBG("No edges found");
(*result_count) = 0;
(*result_tuples) = NULL;
pgr_SPI_finish();
return;
}
PGR_DBG("Total %ld tuples in query:", total_tuples);

clock_t start_t = clock();
PGR_DBG("Starting processing");
do_pgr_floydWarshall(
edges,
total_tuples,
pgr_do_floydWarshall(
edges_sql,
directed,
result_tuples,
result_count,
Expand All @@ -95,7 +74,6 @@ process(
if (notice_msg) pfree(notice_msg);
if (err_msg) pfree(err_msg);

pfree(edges);
pgr_SPI_finish();
}

Expand All @@ -105,41 +83,23 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;

/**************************************************************************/
/* */
IID_t_rt *result_tuples = NULL;

IID_t_rt *result_tuples = NULL;
size_t result_count = 0;
/* */
/**************************************************************************/


if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);


/*********************************************************************/
/* */
// QUERY
// CREATE OR REPLACE FUNCTION pgr_floydWarshalll(
// edges_sql TEXT,
// directed BOOLEAN,
// OUT seq INTEGER,
// OUT from_vid bigint,
// OUT to_vid bigint,
// OUT cost float)


PGR_DBG("Calling process");
process(
text_to_cstring(PG_GETARG_TEXT_P(0)),
PG_GETARG_BOOL(1),
&result_tuples,
&result_count);

/* */
/*********************************************************************/

funcctx->max_calls = result_count;
funcctx->user_fctx = result_tuples;
if (get_call_result_type(fcinfo, NULL, &tuple_desc)
Expand All @@ -161,9 +121,8 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) {
HeapTuple tuple;
Datum result;
Datum *values;
bool* nulls;
bool *nulls;

/*********************************************************************/
values = palloc(3 * sizeof(Datum));
nulls = palloc(3 * sizeof(bool));

Expand All @@ -174,7 +133,6 @@ _pgr_floydwarshall(PG_FUNCTION_ARGS) {
nulls[1] = false;
values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
nulls[2] = false;
/*********************************************************************/

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
Expand Down
55 changes: 6 additions & 49 deletions src/allpairs/johnson.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
#include "c_common/pgdata_getters.h"

#include "drivers/allpairs/johnson_driver.h"

PGDLLEXPORT Datum _pgr_johnson(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(_pgr_johnson);

/******************************************************************************/
/* MODIFY AS NEEDED */

static
void process(
char* edges_sql,
Expand All @@ -54,26 +52,9 @@ void process(
char* notice_msg = NULL;
char* err_msg = NULL;

PGR_DBG("Load data");
Edge_t *edges = NULL;
size_t total_tuples = 0;
pgr_get_edges(edges_sql, &edges, &total_tuples, true, true, &err_msg);
throw_error(err_msg, edges_sql);

if (total_tuples == 0) {
PGR_DBG("No edges found");
(*result_count) = 0;
(*result_tuples) = NULL;
pgr_SPI_finish();
return;
}
PGR_DBG("Total %ld tuples in query:", total_tuples);

PGR_DBG("Starting processing");
clock_t start_t = clock();
do_pgr_johnson(
edges,
total_tuples,
pgr_do_johnson(
edges_sql,
directed,
result_tuples,
result_count,
Expand All @@ -94,47 +75,32 @@ void process(
if (notice_msg) pfree(notice_msg);
if (err_msg) pfree(err_msg);

pfree(edges);
pgr_SPI_finish();
}
/* */
/******************************************************************************/


PGDLLEXPORT Datum
_pgr_johnson(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;

/**************************************************************************/
/* MODIFY AS NEEDED */
/* */

IID_t_rt *result_tuples = NULL;
size_t result_count = 0;
/* */
/**************************************************************************/


if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);


/*********************************************************************/
/* MODIFY AS NEEDED */
// CREATE OR REPLACE FUNCTION pgr_johnson(
// edges_sql TEXT,
// directed BOOLEAN,

PGR_DBG("Calling process");
process(
text_to_cstring(PG_GETARG_TEXT_P(0)),
PG_GETARG_BOOL(1),
&result_tuples,
&result_count);

/* */
/*********************************************************************/

funcctx->max_calls = result_count;
funcctx->user_fctx = result_tuples;
if (get_call_result_type(fcinfo, NULL, &tuple_desc)
Expand All @@ -158,13 +124,6 @@ _pgr_johnson(PG_FUNCTION_ARGS) {
Datum *values;
bool *nulls;

/*********************************************************************/
/* MODIFY AS NEEDED */
// OUT seq BIGINT,
// OUT from_vid BIGINT,
// OUT to_vid BIGINT,
// OUT cost float)

values = palloc(3 * sizeof(Datum));
nulls = palloc(3 * sizeof(bool));

Expand All @@ -176,8 +135,6 @@ _pgr_johnson(PG_FUNCTION_ARGS) {
values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
nulls[2] = false;

/*********************************************************************/

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
Expand Down
36 changes: 1 addition & 35 deletions src/alpha_shape/alphaShape.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_common/time_msg.h"


#include "c_common/pgdata_getters.h"
#include "c_types/geom_text_rt.h"

#include "drivers/alpha_shape/alphaShape_driver.h"
Expand All @@ -50,34 +49,8 @@ static void process(
char* notice_msg = NULL;
char* err_msg = NULL;

Edge_xy_t *edgesArr = NULL;
size_t edgesSize = 0;

pgr_get_edges_xy(edges_sql, &edgesArr, &edgesSize, true, &err_msg);
throw_error(err_msg, edges_sql);

PGR_DBG("total edges %ld", edgesSize);
PGR_DBG("alpha %f", alpha);
#if 0
for (size_t i = 0; i < edgesSize; ++i) {
PGR_DBG("x1=%f y1=%f", edgesArr[i].x1, edgesArr[i].y1);
PGR_DBG("x2=%f y2=%f", edgesArr[i].x2, edgesArr[i].y2);
}
#endif

if (edgesSize < 3) {
if (edgesArr) pfree(edgesArr);
elog(ERROR, "Less than 3 vertices."
" pgr_alphaShape needs at least 3 vertices.");
pgr_SPI_finish();
return;
}

PGR_DBG("Calling alpha-shape driver\n");


do_alphaShape(
edgesArr, edgesSize,
edges_sql,
alpha,

res,
Expand All @@ -97,7 +70,6 @@ static void process(
if (log_msg) pfree(log_msg);
if (notice_msg) pfree(notice_msg);
if (err_msg) pfree(err_msg);
if (edgesArr) pfree(edgesArr);
pgr_SPI_finish();
}

Expand All @@ -108,26 +80,20 @@ Datum _pgr_alphashape(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
TupleDesc tuple_desc;

/**********************************************************************/
GeomText_t *result_tuples = NULL;
size_t result_count = 0;
/**********************************************************************/

if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext;
funcctx = SRF_FIRSTCALL_INIT();
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);

/******************************************************************/

process(
text_to_cstring(PG_GETARG_TEXT_P(0)),
PG_GETARG_FLOAT8(1),
&result_tuples,
&result_count);

/******************************************************************/

funcctx->max_calls = result_count;
funcctx->user_fctx = result_tuples;
if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE)
Expand Down
Loading

0 comments on commit b83423f

Please sign in to comment.