cs_leaf.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* consider A(i,j), node j in ith row subtree and return lca(jprev,j) */
00003 int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf,
00004     int *ancestor, int *jleaf)
00005 {
00006     int q, s, sparent, jprev ;
00007     if (!first || !maxfirst || !prevleaf || !ancestor || !jleaf) return (-1) ;
00008     *jleaf = 0 ;
00009     if (i <= j || first [j] <= maxfirst [i]) return (-1) ;  /* j not a leaf */
00010     maxfirst [i] = first [j] ;      /* update max first[j] seen so far */
00011     jprev = prevleaf [i] ;          /* jprev = previous leaf of ith subtree */
00012     prevleaf [i] = j ;
00013     *jleaf = (jprev == -1) ? 1: 2 ; /* j is first or subsequent leaf */
00014     if (*jleaf == 1) return (i) ;   /* if 1st leaf, q = root of ith subtree */
00015     for (q = jprev ; q != ancestor [q] ; q = ancestor [q]) ;
00016     for (s = jprev ; s != q ; s = sparent)
00017     {
00018         sparent = ancestor [s] ;    /* path compression */
00019         ancestor [s] = q ;
00020     }
00021     return (q) ;                    /* q = least common ancester (jprev,j) */
00022 }


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:56