clones patterns from 'qg' into 'graph'
| 339 | |
| 340 | // clones patterns from 'qg' into 'graph' |
| 341 | QueryGraph *QueryGraph_ExtractPatterns |
| 342 | ( |
| 343 | const QueryGraph *qg, |
| 344 | const cypher_astnode_t **patterns, |
| 345 | uint n |
| 346 | ) { |
| 347 | |
| 348 | // validate inputs |
| 349 | ASSERT(qg != NULL && patterns != NULL); |
| 350 | |
| 351 | // create an empty query graph |
| 352 | uint node_count = QueryGraph_NodeCount(qg); |
| 353 | uint edge_count = QueryGraph_EdgeCount(qg); |
| 354 | QueryGraph *graph = QueryGraph_New(node_count, edge_count); |
| 355 | ASSERT(graph != NULL); |
| 356 | |
| 357 | // extract paths described by each pattern |
| 358 | for(uint i = 0; i < n; i++) { |
| 359 | const cypher_astnode_t *pattern = patterns[i]; |
| 360 | uint npaths = cypher_ast_pattern_npaths(pattern); |
| 361 | for(uint j = 0; j < npaths; j ++) { |
| 362 | const cypher_astnode_t *path = cypher_ast_pattern_get_path(pattern, j); |
| 363 | _QueryGraph_ExtractPath(qg, graph, path); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return graph; |
| 368 | } |
| 369 | |
| 370 | // build a query graph from AST |
| 371 | QueryGraph *BuildQueryGraph |