| 322 | } |
| 323 | |
| 324 | static void addOutgoingNeighbors |
| 325 | ( |
| 326 | SingleSourceCtx *ctx, |
| 327 | LevelConnection *frontier, |
| 328 | uint32_t depth |
| 329 | ) { |
| 330 | EntityID frontierId = INVALID_ENTITY_ID; |
| 331 | if(depth > 1) frontierId = ENTITY_GET_ID(&frontier->edge); |
| 332 | |
| 333 | // Get frontier neighbors. |
| 334 | for(int i = 0; i < ctx->relationCount; i++) { |
| 335 | Graph_GetNodeEdges(ctx->g, &frontier->node, GRAPH_EDGE_DIR_OUTGOING, ctx->relationIDs[i], &ctx->neighbors); |
| 336 | } |
| 337 | |
| 338 | // Add unvisited neighbors to next level. |
| 339 | uint32_t neighborsCount = array_len(ctx->neighbors); |
| 340 | |
| 341 | _SingleSourceCtx_EnsureLevelArrayCap(ctx, depth, neighborsCount); |
| 342 | for(uint32_t i = 0; i < neighborsCount; i++) { |
| 343 | // Don't follow the frontier edge again. |
| 344 | if(frontierId == ENTITY_GET_ID(ctx->neighbors + i)) continue; |
| 345 | // Set the neighbor by following the edge in the correct directoin. |
| 346 | Node neighbor = GE_NEW_NODE(); |
| 347 | Graph_GetNode(ctx->g, Edge_GetDestNodeID(ctx->neighbors + i), &neighbor); |
| 348 | // Add the node and edge to the frontier. |
| 349 | _SingleSourceCtx_AddConnectionToLevel(ctx, depth, &neighbor, (ctx->neighbors + i)); |
| 350 | } |
| 351 | array_clear(ctx->neighbors); |
| 352 | } |
| 353 | |
| 354 | static void addIncomingNeighbors |
| 355 | ( |
no test coverage detected