#include<stdio.h>
#include MUT_H
#include LOG_H
#include BEH_H

/*------------------------------------------------------------------------------
gcNodeBeh	 :effectue un garbage collecteur sur tous les noeuds de systeme
		  en sauvegardant les noeuds pointes par les pNode de la liste 
		  des befig .
-------------------------------------------------------
parametres 	 : pointeur sur befig .
-------------------------------------------------------
return 		 : 1 si ok ;
		   0 si erreur .
------------------------------------------------------------------------------*/
void gcNodeBeh(beh)
befig_list *beh ;
{
struct systemBdd sysBddAux ;
beout_list *out;
bereg_list *reg;
bebus_list *bus;
bebux_list *bux;
binode_list *binode;
beaux_list *aux ;
bemsg_list *mesg;
pNode zeroAux, oneAux ;
pTH pTHNode;

if (sysBdd.pRT->compteur > LARGE)
   {
   pTHNode = createTH(LARGE);
   sysBddAux.pRT = createTableBdd(LARGE);
   }
else
   if (sysBdd.pRT->compteur > MEDIUM)
      {
      pTHNode = createTH(MEDIUM);
      sysBddAux.pRT = createTableBdd(MEDIUM);
      }
   else
      {
      pTHNode = createTH(SMALL);
      sysBddAux.pRT = createTableBdd(SMALL);
      }
     
sysBddAux.pMC = createTabLoc(MEDIUM);
sysBddAux.indiceAT = MAX_PACK ;
sysBddAux.lpAT = NULL ;
zeroAux = initVertexBddAux(0,0,1,&sysBddAux) ;
oneAux = initVertexBddAux(1,0,1,&sysBddAux) ;
addTH(pTHNode,zero,zeroAux);
addTH(pTHNode,one,oneAux);

while(beh)
  {
  out = beh->BEOUT;
  while (out) 
     {
     if (out->NODE)
        {
       out->NODE =  regenereBdd(out->NODE,&sysBddAux,pTHNode);
        }
     out = out->NEXT;
     }

  aux = beh->BEAUX;
  while (aux) 
     {
     if (aux->NODE)
        {
        aux->NODE =  regenereBdd(aux->NODE,&sysBddAux,pTHNode);
        }
     aux = aux->NEXT;
     }

  reg = beh->BEREG;
  while (reg) 
     {
     binode = reg->BINODE ;
     while (binode)
        {
        if (binode->CNDNODE && binode->VALNODE)
           {
           binode->CNDNODE =  regenereBdd(binode->CNDNODE,&sysBddAux,pTHNode);
           binode->VALNODE =  regenereBdd(binode->VALNODE,&sysBddAux,pTHNode);
           }
        binode = binode->NEXT;
        }
     reg = reg->NEXT;
     }

  bus = beh->BEBUS;
  while (bus) 
     {
     binode = bus->BINODE;
     while (binode)
        {
        if (binode->CNDNODE && binode->VALNODE)
           {
           binode->CNDNODE =  regenereBdd(binode->CNDNODE,&sysBddAux,pTHNode);
           binode->VALNODE =  regenereBdd(binode->VALNODE,&sysBddAux,pTHNode);
           }
        binode = binode->NEXT;
        }
     bus = bus->NEXT;
     }

  bux = beh->BEBUX;
  while (bux) 
     {
     binode = bux->BINODE;
     while (binode)
        {
        if (binode->CNDNODE && binode->VALNODE)
           {
           binode->CNDNODE =  regenereBdd(binode->CNDNODE,&sysBddAux,pTHNode);
           binode->VALNODE =  regenereBdd(binode->VALNODE,&sysBddAux,pTHNode);
           }
        binode = binode->NEXT;
        }
     bux = bux->NEXT;
     }

  mesg = beh->BEMSG;
  while (mesg)
     {
     mesg->NODE =  regenereBdd(mesg->NODE,&sysBddAux,pTHNode);
     mesg = mesg->NEXT;
     }

  beh = beh->NEXT ;
  }

destroyBdd(1) ;
destroyTH(pTHNode);
sysBdd.pRT = sysBddAux.pRT ;
sysBdd.pMC = sysBddAux.pMC ;
sysBdd.indiceAT = sysBddAux.indiceAT ;
sysBdd.lpAT = sysBddAux.lpAT ;
sysBdd.pAT = sysBddAux.pAT ;
zero = zeroAux ;
one = oneAux ;
}
