cs_leaf.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* consider A(i,j), node j in ith row subtree and return lca(jprev,j) */
3 int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf,
4  int *ancestor, int *jleaf)
5 {
6  int q, s, sparent, jprev ;
7  if (!first || !maxfirst || !prevleaf || !ancestor || !jleaf) return (-1) ;
8  *jleaf = 0 ;
9  if (i <= j || first [j] <= maxfirst [i]) return (-1) ; /* j not a leaf */
10  maxfirst [i] = first [j] ; /* update max first[j] seen so far */
11  jprev = prevleaf [i] ; /* jprev = previous leaf of ith subtree */
12  prevleaf [i] = j ;
13  *jleaf = (jprev == -1) ? 1: 2 ; /* j is first or subsequent leaf */
14  if (*jleaf == 1) return (i) ; /* if 1st leaf, q = root of ith subtree */
15  for (q = jprev ; q != ancestor [q] ; q = ancestor [q]) ;
16  for (s = jprev ; s != q ; s = sparent)
17  {
18  sparent = ancestor [s] ; /* path compression */
19  ancestor [s] = q ;
20  }
21  return (q) ; /* q = least common ancester (jprev,j) */
22 }
int cs_leaf(int i, int j, const int *first, int *maxfirst, int *prevleaf, int *ancestor, int *jleaf)
Definition: cs_leaf.c:3


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31