Implement giant component and percolation#2746
Implement giant component and percolation#2746Zepeacedust wants to merge 27 commits intoigraph:masterfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2746 +/- ##
==========================================
- Coverage 75.38% 75.37% -0.02%
==========================================
Files 379 380 +1
Lines 55128 55179 +51
Branches 12320 12330 +10
==========================================
+ Hits 41559 41589 +30
- Misses 10017 10040 +23
+ Partials 3552 3550 -2
... and 9 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
| IGRAPH_EXPORT igraph_error_t igraph_bond_percolation(const igraph_t *graph, igraph_vector_t * output); | ||
| IGRAPH_EXPORT igraph_error_t igraph_site_percolation(const igraph_t *graph, igraph_vector_t * output); |
There was a problem hiding this comment.
Let's move these to igraph_components.h
| IGRAPH_EXPORT igraph_error_t igraph_bond_percolation(const igraph_t *graph, igraph_vector_t * output); | ||
| IGRAPH_EXPORT igraph_error_t igraph_site_percolation(const igraph_t *graph, igraph_vector_t * output); |
There was a problem hiding this comment.
First step is to discuss the prototype. It's best if we do this in the issue. I'll post there.
Co-authored-by: Szabolcs Horvát <szhorvat@gmail.com>
src/misc/percolation.c
Outdated
| IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count)); | ||
| igraph_vector_int_t links; | ||
| IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count)); | ||
|
|
||
| int edge_count = igraph_vector_int_size(edges) / 2; | ||
| IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count)); | ||
|
|
||
| for (int i = 0; i < edge_count; i++) { | ||
| igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]); | ||
| VECTOR(*output)[i] = biggest; | ||
| } | ||
| igraph_vector_int_destroy(&sizes); | ||
| igraph_vector_int_destroy(&links); |
There was a problem hiding this comment.
| IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count)); | |
| igraph_vector_int_t links; | |
| IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count)); | |
| int edge_count = igraph_vector_int_size(edges) / 2; | |
| IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count)); | |
| for (int i = 0; i < edge_count; i++) { | |
| igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]); | |
| VECTOR(*output)[i] = biggest; | |
| } | |
| igraph_vector_int_destroy(&sizes); | |
| igraph_vector_int_destroy(&links); | |
| IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count)); | |
| IGRAPH_FINALLY(igraph_vector_int_destroy, &sizes); | |
| igraph_vector_int_t links; | |
| IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count)); | |
| IGRAPH_FINALLY(igraph_vector_int_destroy, &links); | |
| int edge_count = igraph_vector_int_size(edges) / 2; | |
| IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count)); | |
| for (int i = 0; i < edge_count; i++) { | |
| igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]); | |
| VECTOR(*output)[i] = biggest; | |
| } | |
| igraph_vector_int_destroy(&sizes); | |
| igraph_vector_int_destroy(&links); | |
| IGRAPH_FINALLY_CLEAN(2); |
IGRAPH_FINALLY places an object and a destructor on a stack which we call the "finally" stack.
If an error occurs, all destructors currently on the stack are called. This way allocated resources are freed even if the function returns early because of an error.
IGRAPH_FINALLY_CLEAN(2) removes the elements from this stack. This always comes after you manually called destructors, in this case two destructors.
There's a shorthand for the following pattern:
IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count));
IGRAPH_FINALLY(igraph_vector_int_destroy, &sizes);
We usually just write
IGRAPH_VECTOR_INT_INIT_FINALLY(&sizes, vert_count);
This is what you should use here, as well as with vector types, but such a macro is not available for all data structures, so I wanted to show you the separated init + FINALLY pattern as well.
This reverts commit 6ce30a6.
This reverts commit 81c826c.
…ation" This reverts commit ca21e30.
This reverts commit 8a8090a.
This reverts commit b8e3a08.
…rences do not exceed it" This reverts commit 36a629f.
This reverts commit d554968.
This reverts commit 2551886.
This reverts commit 6db2bab.
This reverts commit f25da48.
This reverts commit 068471b.
This reverts commit 0d0e83c.
|
Continued in #2778 |
Closes #2736