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

Function AllPathsCtx_New

src/algorithms/all_paths.c:166–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166AllPathsCtx *AllPathsCtx_New
167(
168 Node *src,
169 Node *dst,
170 Graph *g,
171 int *relationIDs,
172 int relationCount,
173 GRAPH_EDGE_DIR dir,
174 uint minLen,
175 uint maxLen,
176 Record r,
177 FT_FilterNode *ft,
178 uint edge_idx,
179 bool shortest_paths
180) {
181 ASSERT(src != NULL);
182
183 AllPathsCtx *ctx = rm_malloc(sizeof(AllPathsCtx));
184 ctx->g = g;
185 ctx->r = r;
186 ctx->ft = ft;
187 ctx->dir = dir;
188 ctx->edge_idx = edge_idx;
189
190 // Cypher variable path "[:*min..max]"" specifies edge count
191 // While the path constructed here contains only nodes.
192 // As such a path which require min..max edges
193 // should contain min+1..max+1 nodes.
194 ctx->minLen = minLen + 1;
195 ctx->maxLen = maxLen + 1;
196 ctx->relationIDs = relationIDs;
197 ctx->relationCount = relationCount;
198 ctx->levels = array_new(LevelConnection *, 1);
199 ctx->path = Path_New(1);
200 ctx->neighbors = array_new(Edge, 32);
201 ctx->dst = dst;
202 ctx->shortest_paths = shortest_paths;
203 ctx->visited = NULL;
204
205 _AllPathsCtx_EnsureLevelArrayCap(ctx, 0, 1);
206 _AllPathsCtx_AddConnectionToLevel(ctx, 0, src, NULL);
207
208 if(ctx->shortest_paths) {
209 if(dst == NULL) {
210 // If the destination is NULL due to a scenario like a
211 // failed optional match, no results will be produced
212 ctx->maxLen = 0;
213 return ctx;
214 }
215 // get the the minimum length between src and dst
216 // then start the traversal from dst to src
217 int min_path_len = AllShortestPaths_FindMinimumLength(ctx, src, dst);
218 ctx->minLen = min_path_len;
219 ctx->maxLen = min_path_len;
220 ctx->dst = src;
221 if(dir == GRAPH_EDGE_DIR_INCOMING) {
222 ctx->dir = GRAPH_EDGE_DIR_OUTGOING;
223 } else if(dir == GRAPH_EDGE_DIR_OUTGOING) {

Callers 6

test_noPathsFunction · 0.85
test_longest_PathsFunction · 0.85
test_upToThreeLegsPathsFunction · 0.85
test_twoLegPathsFunction · 0.85

Calls 6

rm_mallocFunction · 0.85
Path_NewFunction · 0.85
Record_lengthFunction · 0.85

Tested by 5

test_noPathsFunction · 0.68
test_longest_PathsFunction · 0.68
test_upToThreeLegsPathsFunction · 0.68
test_twoLegPathsFunction · 0.68