1 /* ========================================================================= */
2 /* === AMD_post_tree ======================================================= */
3 /* ========================================================================= */
5 /* ------------------------------------------------------------------------- */
6 /* AMD, Copyright (c) Timothy A. Davis, */
7 /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
8 /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
9 /* web: http://www.cise.ufl.edu/research/sparse/amd */
10 /* ------------------------------------------------------------------------- */
12 /* Post-ordering of a supernodal elimination tree. */
14 #include "amd_internal.h"
16 GLOBAL Int AMD_post_tree
18 Int root, /* root of the tree */
19 Int k, /* start numbering at k */
20 Int Child [ ], /* input argument of size nn, undefined on
21 * output. Child [i] is the head of a link
22 * list of all nodes that are children of node
24 const Int Sibling [ ], /* input argument of size nn, not modified.
25 * If f is a node in the link list of the
26 * children of node i, then Sibling [f] is the
27 * next child of node i.
29 Int Order [ ], /* output order, of size nn. Order [i] = k
30 * if node i is the kth node of the reordered
32 Int Stack [ ] /* workspace of size nn */
34 , Int nn /* nodes are in the range 0..nn-1. */
41 /* --------------------------------------------------------------------- */
42 /* recursive version (Stack [ ] is not used): */
43 /* --------------------------------------------------------------------- */
45 /* this is simple, but can caouse stack overflow if nn is large */
47 for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
49 k = AMD_post_tree (f, k, Child, Sibling, Order, Stack, nn) ;
55 /* --------------------------------------------------------------------- */
56 /* non-recursive version, using an explicit stack */
57 /* --------------------------------------------------------------------- */
59 /* push root on the stack */
65 /* get head of stack */
68 AMD_DEBUG1 (("head of stack "ID" \n", i)) ;
69 ASSERT (i >= 0 && i < nn) ;
71 if (Child [i] != EMPTY)
73 /* the children of i are not yet ordered */
74 /* push each child onto the stack in reverse order */
75 /* so that small ones at the head of the list get popped first */
76 /* and the biggest one at the end of the list gets popped last */
77 for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
81 ASSERT (f >= 0 && f < nn) ;
85 for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
89 AMD_DEBUG1 (("push "ID" on stack\n", f)) ;
90 ASSERT (f >= 0 && f < nn) ;
92 ASSERT (Stack [h] == i) ;
94 /* delete child list so that i gets ordered next time we see it */
99 /* the children of i (if there were any) are already ordered */
100 /* remove i from the stack and order it. Front i is kth front */
102 AMD_DEBUG1 (("pop "ID" order "ID"\n", i, k)) ;
108 AMD_DEBUG1 (("\nStack:")) ;
109 for (h = head ; h >= 0 ; h--)
112 AMD_DEBUG1 ((" "ID, j)) ;
113 ASSERT (j >= 0 && j < nn) ;
115 AMD_DEBUG1 (("\n\n")) ;