NeoPZ
rootls.cpp
Go to the documentation of this file.
1 #include <stdint.h>
2 
3 /* Subroutine */
4 int rootls_ (int64_t *, int64_t *root, int64_t *maxwid,
5  int64_t *, int64_t *adj, int64_t *xadj, int64_t *mask, int64_t *ls,
6  int64_t *xls, int64_t *depth, int64_t *width)
7 //n, root, maxwid, e2, adj, xadj, mask, ls, xls, depth, width
8 {
9  /* System generated locals */
10  int64_t i__1, i__2;
11  /* Local variables */
12  static int64_t node, i, j, lwdth, jstop, lstop, jstrt, lstrt, nc, nbr;
13 
14 
15 /* PURPOSE: */
16 /* -------- */
17 
18 /* Generate rooted level structure using a FORTRAN 77 implementation
19 */
20 /* of the algorithm given by George and Liu */
21 
22 /* INPUT: */
23 /* ------ */
24 
25 /* N - Numbered of nodes */
26 /* ROOT - Root node for level structure */
27 /* MAXWID - Max permissible width ot rooted level structure */
28 /* - Abort assembly of level structure if width is ge MAXWID */
29 /* - Assembly ensured by setting MAXWID =N+1 */
30 /* E2 - Twice the number of edges in the graph = XADJ(N+1)-1 */
31 /* ADJ - Adjacency list for all nodes in graph */
32 /* - List of length 2E where E is the number of edges in */
33 /* the graph and 2E = XADJ(N+1)-1 */
34 /* XADJ - Index vector for adj */
35 /* - Nodes adjacent to node I are found in ADJ(J), where */
36 /* J = XADJ(I), XADJ(I)+1, ..., XADJ(I+1)-1 */
37 /* - Degree of node I is XADJ(I+1)-XADJ(I) */
38 /* MASK - Masking vector for graph */
39 /* - Visible nodes have MASK = 0 */
40 /* LS - Undefined */
41 /* XLS - Undefined */
42 /* DEPTH - Undefined */
43 /* WIDTH - Undefined */
44 
45 /* OUTPUT: */
46 /* ------- */
47 
48 /* N - Unchanged */
49 /* ROOT - Unchanged */
50 /* MAXWID - Unchanged */
51 /* E2 - Unchanged */
52 /* ADJ - Unchanged */
53 /* XADJ - Unchanged */
54 /* MASK - Unchanged */
55 /* LS - List containing a rooted level structure */
56 /* - List of length NC */
57 /* XLS - Index vector for LS */
58 /* - Nodes in level I are found in LS(J), where */
59 /* J=XLS(I), XLS(I)+1, ..., XLS(I+1)-1 */
60 /* - List of max length NC+1 */
61 /* DEPTH - Number of levels in rooted level structure */
62 /* WIDTH - Width of rooted level structure */
63 
64 /* NOTE: If WIDTH ge MAXWID then assembly has been aborted */
65 /* ----- */
66 
67 /* PROGRAMMER: Scott Sloan */
68 /* ----------- */
69 
70 /* LAST MODIFIED: 10 March 1989 Scott Sloan */
71 /* -------------- */
72 
73 /* ***********************************************************************
74  */
75 
76 
77 /* Initialisation */
78 
79  /* Parameter adjustments */
80  --xls;
81  --ls;
82  --mask;
83  --xadj;
84  --adj;
85 
86  /* Function Body */
87  mask[*root] = 1;
88  ls[1] = *root;
89  nc = 1;
90  *width = 1;
91  *depth = 0;
92  lstop = 0;
93  lwdth = 1;
94 L10:
95  if (lwdth > 0)
96  {
97 
98 /* LWDTH is the width of the current level */
99 /* LSTRT points to start of current level */
100 /* LSTOP points to end of current level */
101 /* NC counts the nodes in component */
102 
103  lstrt = lstop + 1;
104  lstop = nc;
105  ++(*depth);
106  xls[*depth] = lstrt;
107 
108 /* Generate next level by finding all visible neighbours */
109 /* of nodes in current level */
110 
111  i__1 = lstop;
112  for (i = lstrt; i <= i__1; ++i)
113  {
114  node = ls[i];
115  jstrt = xadj[node];
116  jstop = xadj[node + 1] - 1;
117  i__2 = jstop;
118  for (j = jstrt; j <= i__2; ++j)
119  {
120  nbr = adj[j];
121  if (mask[nbr] == 0)
122  {
123  ++nc;
124  ls[nc] = nbr;
125  mask[nbr] = 1;
126  }
127 /* L20: */
128  }
129 /* L30: */
130  }
131 
132 /* Compute width of level just assembled and the width of the */
133 /* level structure so far */
134 
135  lwdth = nc - lstop;
136  *width = ((lwdth) > (*width)) ? (lwdth) : (*width);
137 // *width = max(lwdth,*width);
138 
139 /* Abort assembly if level structure is too wide */
140 
141  if (*width >= *maxwid)
142  {
143  goto L35;
144  }
145  goto L10;
146  }
147  xls[*depth + 1] = lstop + 1;
148 
149 /* Reset MASK = 0 for nodes in the level structure */
150 
151 L35:
152  i__1 = nc;
153  for (i = 1; i <= i__1; ++i)
154  {
155  mask[ls[i]] = 0;
156 /* L40: */
157  }
158  return 0;
159 } /* rootls_ */
int rootls_(int64_t *, int64_t *root, int64_t *maxwid, int64_t *, int64_t *adj, int64_t *xadj, int64_t *mask, int64_t *ls, int64_t *xls, int64_t *depth, int64_t *width)
Definition: rootls.cpp:4