| 268 | } |
| 269 | |
| 270 | std::vector<QueryGraph> QueryGraphCollection::mergeGraphs(common::idx_t baseGraphIdx) { |
| 271 | DASSERT(baseGraphIdx < queryGraphs.size()); |
| 272 | auto& baseGraph = queryGraphs[baseGraphIdx]; |
| 273 | std::unordered_set<common::idx_t> mergedGraphIndices; |
| 274 | mergedGraphIndices.insert(baseGraphIdx); |
| 275 | while (true) { |
| 276 | // find graph to merge |
| 277 | common::idx_t graphToMergeIdx = common::INVALID_IDX; |
| 278 | for (auto i = 0u; i < queryGraphs.size(); ++i) { |
| 279 | if (mergedGraphIndices.contains(i)) { // graph has been merged. |
| 280 | continue; |
| 281 | } |
| 282 | if (baseGraph.isConnected(queryGraphs[i])) { // find graph to merge. |
| 283 | graphToMergeIdx = i; |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | if (graphToMergeIdx == common::INVALID_IDX) { // No graph can be merged. Terminate. |
| 288 | break; |
| 289 | } |
| 290 | // Perform merge |
| 291 | baseGraph.merge(queryGraphs[graphToMergeIdx]); |
| 292 | mergedGraphIndices.insert(graphToMergeIdx); |
| 293 | } |
| 294 | std::vector<QueryGraph> finalGraphs; |
| 295 | for (auto i = 0u; i < queryGraphs.size(); ++i) { |
| 296 | if (i == baseGraphIdx) { |
| 297 | finalGraphs.push_back(baseGraph); |
| 298 | continue; |
| 299 | } |
| 300 | if (mergedGraphIndices.contains(i)) { |
| 301 | continue; |
| 302 | } |
| 303 | finalGraphs.push_back(std::move(queryGraphs[i])); |
| 304 | } |
| 305 | return finalGraphs; |
| 306 | } |
| 307 | |
| 308 | bool QueryGraphCollection::contains(const std::string& name) const { |
| 309 | for (auto& queryGraph : queryGraphs) { |