Repository navigation
Merge the smaller component into the larger one when an edge joins two components - #502
Conversation
…o components An edge moved every vertex of the destination's component into the source's component, whatever their sizes. An edge from a new vertex into a big component therefore moved the whole component, which made building a graph quadratic in its size. The smaller component moves now (union by size): a graph of 10000 vertices from an edge list takes 55 ms instead of 633 ms, and 10000 calls of EdgeFromNewVertex 39 ms instead of 1830 ms. Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 29 |
| Duplication | 0 |
🟢 Coverage 100.00% diff coverage · +0.01% coverage variation
Metric Results Coverage variation ✅ +0.01% coverage variation (-1.00%) Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (fc7b456) 14637 13129 89.70% Head commit (62ba13f) 14639 (+2) 13132 (+3) 89.71% (+0.01%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#502) 2 2 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #502 +/- ##
=======================================
Coverage 86.96% 86.97%
=======================================
Files 59 59
Lines 14637 14639 +2
Branches 2267 2268 +1
=======================================
+ Hits 12729 12732 +3
+ Misses 1508 1507 -1
Partials 400 400
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Speed-up from the Cython probe: profiling the Graph benchmark showed that 160 of 170 ms went into merging components, not into anything Cython could compile away. This PR fixes it in plain Python.
Changes
pyTooling.Graph:set.addcalls for 6000 edges.Best of 5, Python 3.14, Linux, fresh process per side:
devgraph_n1000_m1500edge listgraph_n10000_m15000edge listroot.EdgeFromNewVertex(i)(flat)vertex.EdgeFromNewVertex(i)(linear chain)root.EdgeToNewVertex(i)(merge was already cheap)Documentation
doc/News.rst: the change, with the numbers.Unit Tests
Components:test_Merge_SmallIntoLarge,test_Merge_LargeIntoSmall,test_Merge_EqualSize- which component survives, that the graph has one component and that it holds every vertex.tests/performance/Graph/Graph.py:EdgeLinking.test_LinkFromNewVertex_Flatandtest_LinkFromNewVertex_Linear, the direction that was quadratic (the existing two tests link to a new vertex).