MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / mergeGraphs

Method mergeGraphs

src/binder/query/query_graph.cpp:270–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270std::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
308bool QueryGraphCollection::contains(const std::string& name) const {
309 for (auto& queryGraph : queryGraphs) {

Callers

nothing calls this directly

Calls 6

isConnectedMethod · 0.80
sizeMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45
mergeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected