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

Function SPpaths_single_minimal

src/procedures/proc_sp_paths.c:560–591  ·  view source on GitHub ↗

find the single minimal weighted path

Source from the content-addressed store, hash-verified

558
559// find the single minimal weighted path
560static void SPpaths_single_minimal
561(
562 SinglePairCtx *ctx
563) {
564 // initialize the result path to worst path
565 ctx->single.path = NULL;
566 ctx->single.weight = DBL_MAX;
567 ctx->single.cost = DBL_MAX;
568
569 // get first path
570 WeightedPath p = {0};
571 SPpaths_next(ctx, &p, DBL_MAX);
572
573 // iterate over all paths
574 while (p.path != NULL) {
575 // if the current path is better replace it
576 if(p.weight < ctx->single.weight ||
577 p.cost < ctx->single.cost ||
578 (p.cost == ctx->single.cost &&
579 Path_Len(p.path) < Path_Len(ctx->single.path))) {
580 if(ctx->single.path != NULL) {
581 Path_Free(ctx->single.path);
582 }
583 ctx->single.path = Path_Clone(p.path);
584 ctx->single.weight = p.weight;
585 ctx->single.cost = p.cost;
586 }
587
588 // get next path where path weight is <= result weight
589 SPpaths_next(ctx, &p, ctx->single.weight);
590 }
591}
592
593static void inline _add_path
594(

Callers 1

Proc_SPpathsInvokeFunction · 0.85

Calls 4

SPpaths_nextFunction · 0.85
Path_LenFunction · 0.85
Path_FreeFunction · 0.85
Path_CloneFunction · 0.85

Tested by

no test coverage detected