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

Function addOutgoingNeighbors

src/algorithms/all_paths.c:43–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void addOutgoingNeighbors
44(
45 AllPathsCtx *ctx,
46 LevelConnection *frontier,
47 uint32_t depth
48) {
49 EntityID frontierId = INVALID_ENTITY_ID;
50 if(depth > 1) frontierId = ENTITY_GET_ID(&frontier->edge);
51
52 // Get frontier neighbors.
53 for(int i = 0; i < ctx->relationCount; i++) {
54 Graph_GetNodeEdges(ctx->g, &frontier->node, GRAPH_EDGE_DIR_OUTGOING, ctx->relationIDs[i], &ctx->neighbors);
55 }
56
57 // Add unvisited neighbors to next level.
58 uint32_t neighborsCount = array_len(ctx->neighbors);
59
60 //--------------------------------------------------------------------------
61 // apply filter to edge
62 //--------------------------------------------------------------------------
63 if(ctx->ft) {
64 for(uint32_t i = 0; i < neighborsCount; i++) {
65 Edge e = ctx->neighbors[i];
66
67 // update the record with the current edge
68 Record_AddEdge(ctx->r, ctx->edge_idx, e);
69
70 // drop edge if it doesn't passes filter
71 if(FilterTree_applyFilters(ctx->ft, ctx->r) != FILTER_PASS) {
72 array_del_fast(ctx->neighbors, i);
73 i--;
74 neighborsCount--;
75 }
76 }
77 }
78
79 _AllPathsCtx_EnsureLevelArrayCap(ctx, depth, neighborsCount);
80 for(uint32_t i = 0; i < neighborsCount; i++) {
81 // Don't follow the frontier edge again.
82 if(frontierId == ENTITY_GET_ID(ctx->neighbors + i)) continue;
83 // Set the neighbor by following the edge in the correct directoin.
84 Node neighbor = GE_NEW_NODE();
85 Graph_GetNode(ctx->g, Edge_GetDestNodeID(ctx->neighbors + i), &neighbor);
86 // Add the node and edge to the frontier.
87 _AllPathsCtx_AddConnectionToLevel(ctx, depth, &neighbor, (ctx->neighbors + i));
88 }
89 array_clear(ctx->neighbors);
90}
91
92void addIncomingNeighbors
93(

Callers 1

addNeighborsFunction · 0.70

Calls 8

Graph_GetNodeEdgesFunction · 0.85
array_lenFunction · 0.85
Record_AddEdgeFunction · 0.85
FilterTree_applyFiltersFunction · 0.85
Graph_GetNodeFunction · 0.85
Edge_GetDestNodeIDFunction · 0.85

Tested by

no test coverage detected