MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / SSpaths_single_minimal

Function SSpaths_single_minimal

src/procedures/proc_ss_paths.c:551–582  ·  view source on GitHub ↗

find the single minimal weighted path

Source from the content-addressed store, hash-verified

549
550// find the single minimal weighted path
551static void SSpaths_single_minimal
552(
553 SingleSourceCtx *ctx
554) {
555 // initialize the result path to worst path
556 ctx->single.path = NULL;
557 ctx->single.weight = DBL_MAX;
558 ctx->single.cost = DBL_MAX;
559
560 // get first path
561 WeightedPath p = {0};
562 SSpaths_next(ctx, &p, DBL_MAX);
563
564 // iterate over all paths
565 while (p.path != NULL) {
566 // if the current path is better replace it
567 if(p.weight < ctx->single.weight ||
568 p.cost < ctx->single.cost ||
569 (p.cost == ctx->single.cost &&
570 Path_Len(p.path) < Path_Len(ctx->single.path))) {
571 if(ctx->single.path != NULL) {
572 Path_Free(ctx->single.path);
573 }
574 ctx->single.path = Path_Clone(p.path);
575 ctx->single.weight = p.weight;
576 ctx->single.cost = p.cost;
577 }
578
579 // get next path where path weight is <= result weight
580 SSpaths_next(ctx, &p, ctx->single.weight);
581 }
582}
583
584static void inline _add_path
585(

Callers 1

Proc_SSpathsInvokeFunction · 0.85

Calls 4

SSpaths_nextFunction · 0.85
Path_LenFunction · 0.85
Path_FreeFunction · 0.85
Path_CloneFunction · 0.85

Tested by

no test coverage detected