Skip to content

Commit eb3a92b

Browse files
claudekrlmlr
authored andcommitted
nfc: igraph_rewire_edges() uses igraph_edge_type_sw_t parameter
igraph_rewire_edges() now takes an igraph_edge_type_sw_t allowed_edge_types parameter instead of separate loops and multiple boolean parameters. Callers (igraph_watts_strogatz_game, igraph_rewire_directed_edges) are updated to convert their boolean parameters to the new enum type. Proof of work: git diff --shortstat HEAD..next (before -> after) Before: 1428 files changed, 77325 insertions(+), 18759 deletions(-) After: 1427 files changed, 77302 insertions(+), 18749 deletions(-) Proof of work: git diff --numstat HEAD..next (before -> after) add-b del-b add-a del-a file 11 0 0 0 changelog/1-nfc/0470-rewire-edges.md 21 42 20 41 include/igraph_games.h 13 19 5 13 src/operators/rewire_edges.c 9 10 9 10 src/games/watts_strogatz.c 5 4 4 3 tests/unit/coloring.c 447 440 445 438 interfaces/functions.yaml https://claude.ai/code/session_01LYRnwPbhe4AY8VJunwKTzq
1 parent 9373961 commit eb3a92b

6 files changed

Lines changed: 49 additions & 13 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# igraph_rewire_edges()
2+
3+
**Category**: Graph generators
4+
5+
`igraph_rewire_edges()` uses an `igraph_edge_type_sw_t allowed_edge_types` parameter instead of `loops` and `multiple`.
6+
7+
---
8+
9+
**Original changelog wording:**
10+
11+
> `igraph_rewire_edges()` uses an `igraph_edge_type_sw_t allowed_edge_types` parameter instead of `loops` and `multiple`.
12+
13+
---
14+
15+
## Proof of work: `git diff --numstat HEAD..next`
16+
17+
Before and after the change, side by side (add-before, del-before, add-after, del-after, file):
18+
19+
```
20+
add-b del-b add-a del-a file
21+
11 0 0 0 changelog/1-nfc/0470-rewire-edges.md
22+
21 42 20 41 include/igraph_games.h
23+
13 19 5 13 src/operators/rewire_edges.c
24+
9 10 9 10 src/games/watts_strogatz.c
25+
5 4 4 3 tests/unit/coloring.c
26+
447 440 445 438 interfaces/functions.yaml
27+
```
28+
29+
Notes on remaining differences:
30+
- `changelog/1-nfc/0470-rewire-edges.md`: Fully ported (0/0 remaining). The proof-of-work section exists only on `main-dev`.
31+
- `include/igraph_games.h`: Remaining differences (20/41) are unrelated changes (copyright header, `__BEGIN_DECLS`→`IGRAPH_BEGIN_C_DECLS`, other function signature changes from later entries like `igraph_watts_strogatz_game`, `igraph_static_fitness_game`, `igraph_sbm_game`, `igraph_correlated_game`, removed deprecated functions).
32+
- `src/operators/rewire_edges.c`: Remaining differences (5/13) are unrelated NFC changes (vim modeline removal, copyright header, `igraph_vector_int_order1`→`igraph_i_vector_int_order` rename, `IGRAPH_I_ATTRIBUTE_COPY` macro→function call, blank line removals).
33+
- `src/games/watts_strogatz.c`: Unchanged (9/10) because the `igraph_watts_strogatz_game` signature change is a separate entry (0560). The internal call was adapted to convert booleans to `igraph_edge_type_sw_t`.
34+
- `tests/unit/coloring.c`: Remaining differences (4/3) are unrelated (copyright header, `igraph_lcf`→`igraph_lcf_small` rename, `igraph_bipartite_game_gnm` signature change).
35+
- `interfaces/functions.yaml`: Remaining differences (445/438) are from many other function entries across the file.

‎include/igraph_games.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ IGRAPH_EXPORT igraph_error_t igraph_asymmetric_preference_game(igraph_t *graph,
137137
igraph_bool_t loops);
138138

139139
IGRAPH_EXPORT igraph_error_t igraph_rewire_edges(igraph_t *graph, igraph_real_t prob,
140-
igraph_bool_t loops, igraph_bool_t multiple);
140+
igraph_edge_type_sw_t allowed_edge_types);
141141
IGRAPH_EXPORT igraph_error_t igraph_rewire_directed_edges(igraph_t *graph, igraph_real_t prob,
142142
igraph_bool_t loops, igraph_neimode_t mode);
143143

‎interfaces/functions.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ igraph_asymmetric_preference_game:
329329
330330
igraph_rewire_edges:
331331
PARAMS: |-
332-
INOUT GRAPH graph, REAL prob, BOOLEAN loops=False,
333-
BOOLEAN multiple=False
332+
INOUT GRAPH graph, REAL prob,
333+
EDGE_TYPE_SW allowed_edge_types=SIMPLE
334334
335335
igraph_rewire_directed_edges:
336336
PARAMS: |-

‎src/games/watts_strogatz.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ igraph_error_t igraph_watts_strogatz_game(igraph_t *graph, igraph_int_t dim,
112112

113113
/* Rewire the edges then */
114114

115-
IGRAPH_CHECK(igraph_rewire_edges(graph, p, loops, multiple));
115+
IGRAPH_CHECK(igraph_rewire_edges(graph, p, (loops ? IGRAPH_LOOPS_SW : IGRAPH_SIMPLE_SW) | (multiple ? IGRAPH_MULTI_SW : IGRAPH_SIMPLE_SW)));
116116

117117
IGRAPH_FINALLY_CLEAN(1);
118118
return IGRAPH_SUCCESS;

‎src/operators/rewire_edges.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/* -*- mode: C -*- */
21
/* vim:set ts=4 sw=4 sts=4 et: */
32
/*
4-
IGraph library.
3+
igraph library.
54
Copyright (C) 2003-2021 The igraph development team
65
76
This program is free software; you can redistribute it and/or modify
@@ -29,6 +28,7 @@
2928
#include "igraph_random.h"
3029

3130
#include "graph/attributes.h"
31+
#include "misc/graphicality.h"
3232

3333
static igraph_error_t igraph_i_rewire_edges_no_multiple(igraph_t *graph, igraph_real_t prob,
3434
igraph_bool_t loops,
@@ -205,10 +205,8 @@ static igraph_error_t igraph_i_rewire_edges_no_multiple(igraph_t *graph, igraph_
205205
* directed or undirected.
206206
* \param prob The rewiring probability a constant between zero and
207207
* one (inclusive).
208-
* \param loops Boolean, whether loop edges are allowed in the new
209-
* graph, or not.
210-
* \param multiple Boolean, whether multiple edges are allowed in the
211-
* new graph.
208+
* \param allowed_edge_types Controls whether multi-edges and self-loops
209+
* are allowed in the new graph. See \ref igraph_edge_type_sw_t.
212210
* \return Error code.
213211
*
214212
* \sa \ref igraph_watts_strogatz_game() uses this function for the
@@ -217,14 +215,17 @@ static igraph_error_t igraph_i_rewire_edges_no_multiple(igraph_t *graph, igraph_
217215
* Time complexity: O(|V|+|E|).
218216
*/
219217
igraph_error_t igraph_rewire_edges(igraph_t *graph, igraph_real_t prob,
220-
igraph_bool_t loops, igraph_bool_t multiple) {
218+
igraph_edge_type_sw_t allowed_edge_types) {
221219

222220
igraph_t newgraph;
223221
igraph_int_t no_of_edges = igraph_ecount(graph);
224222
igraph_int_t no_of_nodes = igraph_vcount(graph);
225223
igraph_int_t endpoints = no_of_edges * 2;
226224
igraph_int_t to_rewire;
227225
igraph_vector_int_t edges;
226+
igraph_bool_t loops, multiple;
227+
228+
IGRAPH_CHECK(igraph_i_edge_type_to_loops_multiple(allowed_edge_types, &loops, &multiple));
228229

229230
if (prob < 0 || prob > 1) {
230231
IGRAPH_ERROR("Rewiring probability should be between zero and one",
@@ -384,7 +385,7 @@ igraph_error_t igraph_rewire_directed_edges(igraph_t *graph, igraph_real_t prob,
384385
*graph = newgraph;
385386

386387
} else {
387-
IGRAPH_CHECK(igraph_rewire_edges(graph, prob, loops, /* multiple = */ 1));
388+
IGRAPH_CHECK(igraph_rewire_edges(graph, prob, IGRAPH_MULTI_SW | (loops ? IGRAPH_LOOPS_SW : IGRAPH_SIMPLE_SW)));
388389
}
389390

390391
return IGRAPH_SUCCESS;

‎tests/unit/coloring.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void test_graph_large(void) {
104104
run_tests(&graph, false);
105105

106106
/* graph with loops and parallel edges */
107-
igraph_rewire_edges(&graph, 1.0, true, true);
107+
igraph_rewire_edges(&graph, 1.0, IGRAPH_LOOPS_SW | IGRAPH_MULTI_SW);
108108
printf("Testing large graph with loops and multi-edges\n");
109109
run_tests(&graph, false);
110110

0 commit comments

Comments
 (0)