3 #define HEAD(k,j) (ata ? head [k] : j) 4 #define NEXT(J) (ata ? next [J] : -1) 7 int i, k, p, m = AT->
n, n = AT->
m, *ATp = AT->
p, *ATi = AT->
i ;
8 *head = w+4*n, *next = w+5*n+1 ;
9 for (k = 0 ; k < n ; k++) w [post [k]] = k ;
10 for (i = 0 ; i < m ; i++)
12 for (k = n, p = ATp[i] ; p < ATp[i+1] ; p++) k =
CS_MIN (k, w [ATi[p]]);
13 (*next) [i] = (*head) [k] ;
17 int *
cs_counts (
const cs *
A,
const int *parent,
const int *post,
int ata)
19 int i, j, k, n, m, J, s, p, q, jleaf, *ATp, *ATi, *maxfirst, *prevleaf,
20 *ancestor, *
head = NULL, *
next = NULL, *colcount, *w, *first, *delta ;
22 if (!
CS_CSC (A) || !parent || !post)
return (NULL) ;
24 s = 4*n + (ata ? (n+m+1) : 0) ;
25 delta = colcount = (
int*)
cs_malloc (n,
sizeof (
int)) ;
28 if (!AT || !colcount || !w)
return (
cs_idone (colcount, AT, w, 0)) ;
29 ancestor = w ; maxfirst = w+n ; prevleaf = w+2*n ; first = w+3*n ;
30 for (k = 0 ; k < s ; k++) w [k] = -1 ;
31 for (k = 0 ; k < n ; k++)
34 delta [j] = (first [j] == -1) ? 1 : 0 ;
35 for ( ; j != -1 && first [j] == -1 ; j = parent [j]) first [j] = k ;
37 ATp = AT->
p ; ATi = AT->
i ;
38 if (ata)
init_ata (AT, post, w, &head, &next) ;
39 for (i = 0 ; i < n ; i++) ancestor [i] = i ;
40 for (k = 0 ; k < n ; k++)
43 if (parent [j] != -1) delta [parent [j]]-- ;
44 for (J =
HEAD (k,j) ; J != -1 ; J =
NEXT (J))
46 for (p = ATp [J] ; p < ATp [J+1] ; p++)
49 q =
cs_leaf (i, j, first, maxfirst, prevleaf, ancestor, &jleaf);
50 if (jleaf >= 1) delta [j]++ ;
51 if (jleaf == 2) delta [q]-- ;
54 if (parent [j] != -1) ancestor [j] = parent [j] ;
56 for (j = 0 ; j < n ; j++)
58 if (parent [j] != -1) colcount [parent [j]] += colcount [j] ;
60 return (
cs_idone (colcount, AT, w, 1)) ;
cs * cs_transpose(const cs *A, int values)
int * cs_counts(const cs *A, const int *parent, const int *post, int ata)
int cs_leaf(int i, int j, const int *first, int *maxfirst, int *prevleaf, int *ancestor, int *jleaf)
int * cs_idone(int *p, cs *C, void *w, int ok)
void * cs_malloc(int n, size_t size)
SegmentReturnType head(Index vecSize)
Expression next(const Expression &arg)
static void init_ata(cs *AT, const int *post, int *w, int **head, int **next)