Skip to content

Commit 699837c

Browse files
committed
refactor: prettier code in igraphmodule_Graph_community_edge_betweenness
1 parent 12036b7 commit 699837c

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/_igraph/graphobject.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13048,49 +13048,52 @@ PyObject *igraphmodule_Graph_community_edge_betweenness(igraphmodule_GraphObject
1304813048
PyObject *res, *qs, *ms;
1304913049
igraph_matrix_int_t merges;
1305013050
igraph_vector_t q;
13051-
igraph_vector_t *weights = 0;
13051+
igraph_vector_t *weights = NULL;
1305213052

13053-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &directed, &weights_o))
13053+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &directed, &weights_o)) {
1305413054
return NULL;
13055+
}
1305513056

13056-
if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights,
13057-
ATTRIBUTE_TYPE_EDGE)) return NULL;
13057+
if (igraphmodule_attrib_to_vector_t(weights_o, self, &weights, ATTRIBUTE_TYPE_EDGE)) {
13058+
return NULL;
13059+
}
1305813060

1305913061
if (igraph_matrix_int_init(&merges, 0, 0)) {
13060-
if (weights != 0) {
13062+
if (weights) {
1306113063
igraph_vector_destroy(weights); free(weights);
1306213064
}
1306313065
return igraphmodule_handle_igraph_error();
1306413066
}
1306513067

1306613068
if (igraph_vector_init(&q, 0)) {
1306713069
igraph_matrix_int_destroy(&merges);
13068-
if (weights != 0) {
13070+
if (weights) {
1306913071
igraph_vector_destroy(weights); free(weights);
1307013072
}
1307113073
return igraphmodule_handle_igraph_error();
1307213074
}
1307313075

1307413076
if (igraph_community_edge_betweenness(&self->g,
13075-
/* removed_edges = */ 0,
13076-
/* edge_betweenness = */ 0,
13077+
/* removed_edges = */ NULL,
13078+
/* edge_betweenness = */ NULL,
1307713079
/* merges = */ &merges,
13078-
/* bridges = */ 0,
13080+
/* bridges = */ NULL,
1307913081
/* modularity = */ &q,
13080-
/* membership = */ 0,
13082+
/* membership = */ NULL,
1308113083
PyObject_IsTrue(directed),
1308213084
weights,
13083-
/* lengths = */ 0)) {
13084-
igraphmodule_handle_igraph_error();
13085-
if (weights != 0) {
13085+
/* lengths = */ NULL)) {
13086+
13087+
igraph_vector_destroy(&q);
13088+
igraph_matrix_int_destroy(&merges);
13089+
if (weights) {
1308613090
igraph_vector_destroy(weights); free(weights);
1308713091
}
13088-
igraph_matrix_int_destroy(&merges);
13089-
igraph_vector_destroy(&q);
13090-
return NULL;
13092+
13093+
return igraphmodule_handle_igraph_error();;
1309113094
}
1309213095

13093-
if (weights != 0) {
13096+
if (weights) {
1309413097
igraph_vector_destroy(weights); free(weights);
1309513098
}
1309613099

@@ -13101,7 +13104,7 @@ PyObject *igraphmodule_Graph_community_edge_betweenness(igraphmodule_GraphObject
1310113104
return NULL;
1310213105
}
1310313106

13104-
ms=igraphmodule_matrix_int_t_to_PyList(&merges);
13107+
ms = igraphmodule_matrix_int_t_to_PyList(&merges);
1310513108
igraph_matrix_int_destroy(&merges);
1310613109

1310713110
if (ms == NULL) {

0 commit comments

Comments
 (0)