-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadjacents.c
64 lines (59 loc) · 2.03 KB
/
adjacents.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Copyright (C) 2014 William M. Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "graph.h"
void graph_find_adjacents (const graph_t * graph, graph_t * subgraph)
{
subgraph->nadjacents = 0;
/* printf ("--> adj call\n"); */
size_t i, j, k;
for (i = 0; i < subgraph->max_nvertices; i++)
{
if (subgraph->nvedges[i] > 0 && subgraph->nvedges[i] != graph->nvedges[i])
{
for (j = 0, k = 0; j < graph->nvedges[i]; j++) // && graph->edges[i][j] < i
{
/* if (k >= subgraph->nvedges[i]) */
/* { */
/* printf ("adj (%zu -- %u) [%zu]\n", i, graph->edges[i][j], k); */
/* } */
/* else if (subgraph->edges[i][k] > graph->edges[i][j]) */
/* { */
/* printf ("adj (%zu -- %u / %u) [%zu]\n", i, graph->edges[i][j], subgraph->edges[i][k], k); */
/* } */
if (k >= subgraph->nvedges[i] || subgraph->edges[i][k] > graph->edges[i][j])
{
/* printf ("adj yes\n"); */
if (graph->edges[i][j] > i)
{
set_edge (subgraph->adjacents[subgraph->nadjacents], i, graph->edges[i][j]);
subgraph->nadjacents++;
}
else if (subgraph->nvedges[graph->edges[i][j]] == 0)
{
set_edge (subgraph->adjacents[subgraph->nadjacents], graph->edges[i][j], i);
subgraph->nadjacents++;
}
}
else
{
k++;
}
}
}
}
}