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

Function QueryGraph_AddPath

src/graph/query_graph.c:278–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278void QueryGraph_AddPath
279(
280 QueryGraph *qg, // query graph to add path to
281 const cypher_astnode_t *path, // path to add
282 bool only_shortest // interested only in the shortest paths
283) {
284 AST *ast = QueryCtx_GetAST();
285 uint nelems = cypher_ast_pattern_path_nelements(path);
286 // introduce nodes first
287 // nodes are positioned at every even offset
288 // into the path (0, 2, ...)
289 for(uint i = 0; i < nelems; i += 2) {
290 const cypher_astnode_t *ast_node =
291 cypher_ast_pattern_path_get_element(path, i);
292 _QueryGraphAddNode(qg, ast_node);
293 }
294
295 // every odd offset corresponds to an edge in a path
296 for(uint i = 1; i < nelems; i += 2) {
297 // retrieve the QGNode corresponding to the node left of this edge
298 const cypher_astnode_t *l_node =
299 cypher_ast_pattern_path_get_element(path, i - 1);
300 const char *l_alias = AST_ToString(l_node);
301 QGNode *left = QueryGraph_GetNodeByAlias(qg, l_alias);
302
303 // retrieve the QGNode corresponding to the node right of this edge
304 const cypher_astnode_t *r_node =
305 cypher_ast_pattern_path_get_element(path, i + 1);
306 const char *r_alias = AST_ToString(r_node);
307 QGNode *right = QueryGraph_GetNodeByAlias(qg, r_alias);
308
309 // retrieve the AST reference to this edge
310 const cypher_astnode_t *edge =
311 cypher_ast_pattern_path_get_element(path, i);
312 _QueryGraphAddEdge(qg, edge, left, right, only_shortest);
313 }
314}
315
316// clones path from 'qg' into 'graph'
317QueryGraph *QueryGraph_ExtractPaths

Callers 1

BuildQueryGraphFunction · 0.85

Calls 5

QueryCtx_GetASTFunction · 0.85
_QueryGraphAddNodeFunction · 0.85
AST_ToStringFunction · 0.85
_QueryGraphAddEdgeFunction · 0.85

Tested by

no test coverage detected