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

Function SSpaths_all_minimal

src/procedures/proc_ss_paths.c:515–548  ·  view source on GitHub ↗

get all minimal paths (all paths with the same weight)

Source from the content-addressed store, hash-verified

513
514// get all minimal paths (all paths with the same weight)
515static void SSpaths_all_minimal
516(
517 SingleSourceCtx *ctx
518) {
519 // initialize array that contains the result
520 ctx->array = array_new(WeightedPath, 0);
521
522 // get first path
523 WeightedPath p = {0};
524 double max_weight = DBL_MAX;
525 SSpaths_next(ctx, &p, max_weight);
526
527 // iterate over all paths
528 while (p.path != NULL) {
529 // if current path is better and the array is not empty clear it
530 uint count = array_len(ctx->array);
531 if(count > 0 && p.weight < ctx->array[0].weight) {
532 for (uint i = 0; i < array_len(ctx->array); i++) {
533 Path_Free(ctx->array[i].path);
534 }
535 array_clear(ctx->array);
536 }
537
538 // add the path to the result array
539 p.path = Path_Clone(p.path);
540 array_append(ctx->array, p);
541
542 // update max weight
543 max_weight = p.weight;
544
545 // get next path where path weight is <= max_weight
546 SSpaths_next(ctx, &p, max_weight);
547 }
548}
549
550// find the single minimal weighted path
551static void SSpaths_single_minimal

Callers 1

Proc_SSpathsInvokeFunction · 0.85

Calls 4

SSpaths_nextFunction · 0.85
array_lenFunction · 0.85
Path_FreeFunction · 0.85
Path_CloneFunction · 0.85

Tested by

no test coverage detected