model_server/edge/src/sugitopsort.cxx
/*
 *FindTopNodes
 *	Retuns a list of the nodes which should be on level 0
 *	This includes all nodes with 0 predecessors and those for whom the
 *	number of pred - # incoming reversed edges + # outgoing reversed edges
 *	is 0 (because these have 0 predecessors from later in the graph).
 */
FindTopNodes
Retuns a list of the nodes which should be on level 0
This includes all nodes with 0 predecessors and those for whom the
number of pred - # incoming reversed edges + # outgoing reversed edges
is 0 (because these have 0 predecessors from later in the graph).
FindTopNodes Retuns a list of the nodes which should be on level 0 This includes all nodes with 0 predecessors and those for whom the number of pred - # incoming reversed edges + # outgoing reversed edges is 0 ( because these have 0 predecessors from later in the graph ) .
nlist* FindTopNodes(graph* g)
{
  nlist* l = new nlist;
  for (node* n = g->getheadnode(); n; n = n->getnextnode()) {
      int pred = n->countpred();
      slist_iterator_forw iterp(*(slist*) n->getpredlist());
      node* p;
      while(p = (node*)iterp())
        if (((g->find_edge(p,n) != NULL) && (g->find_edge(p,n)->isreversed()))) 
	    pred -= 1;
      slist_iterator_forw iters(*(slist*) n->getsucclist());
      node* s;
      while(s = (node*)iters())
       if ((g->find_edge(n,s) != NULL) && (g->find_edge(n,s)->isreversed())) 		    pred += 1;
      if (pred == 0)
        l->append(n);
    }
  return l;
}
nlist * FindTopNodes ( graph * g ) { nlist * l = new nlist ; for ( node * n = g -> getheadnode ( ) ; n ; n = n -> getnextnode ( ) ) { int pred = n -> countpred ( ) ; slist_iterator_forw iterp ( * ( slist * ) n -> getpredlist ( ) ) ; node * p ; while ( p = ( node * ) iterp ( ) ) if ( ( ( g -> find_edge ( p , n ) != NULL ) && ( g -> find_edge ( p , n ) -> isreversed ( ) ) ) ) pred -= 1 ; slist_iterator_forw iters ( * ( slist * ) n -> getsucclist ( ) ) ; node * s ; while ( s = ( node * ) iters ( ) ) if ( ( g -> find_edge ( n , s ) != NULL ) && ( g -> find_edge ( n , s ) -> isreversed ( ) ) ) pred += 1 ; if ( pred == 0 ) l -> append ( n ) ; } return l ; }
FindTopNodes
      Retuns a list of the nodes which should be on level 0
      This includes all nodes with 0 predecessors and those for whom the
      number of pred - # incoming reversed edges + # outgoing reversed edges
      is 0 (because these have 0 predecessors from later in the graph).
FindTopNodes Retuns a list of the nodes which should be on level 0 This includes all nodes with 0 predecessors and those for whom the number of pred - # incoming reversed edges + # outgoing reversed edges is 0 ( because these have 0 predecessors from later in the graph ) .