| 20 | } |
| 21 | |
| 22 | void clean_topo(struct gossmap *map, bool remove_singles) |
| 23 | { |
| 24 | struct gossmap_node *n, *next; |
| 25 | bool *visited; |
| 26 | |
| 27 | /* Remove channels which are not enabled in both dirs. */ |
| 28 | for (struct gossmap_chan *c = gossmap_first_chan(map); |
| 29 | c; |
| 30 | c = gossmap_next_chan(map, c)) { |
| 31 | if (!c->half[0].enabled || !c->half[1].enabled) { |
| 32 | gossmap_remove_chan(map, c); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | if (remove_singles) { |
| 37 | for (n = gossmap_first_node(map); n; n = next) { |
| 38 | next = gossmap_next_node(map, n); |
| 39 | if (n->num_chans == 1) |
| 40 | gossmap_remove_node(map, n); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /* Remove isolated nodes (we assume first isn't isolated!) */ |
| 45 | visited = tal_arrz(NULL, bool, gossmap_max_node_idx(map)); |
| 46 | visit(map, gossmap_first_node(map), visited); |
| 47 | |
| 48 | for (n = gossmap_first_node(map); n; n = next) { |
| 49 | next = gossmap_next_node(map, n); |
| 50 | if (!visited[gossmap_node_idx(map, n)]) |
| 51 | gossmap_remove_node(map, n); |
| 52 | } |
| 53 | tal_free(visited); |
| 54 | } |
no test coverage detected