| 164 | } |
| 165 | |
| 166 | AllPathsCtx *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) { |