Re: SRF written in C - Mailing list pgsql-general

From Felipe de Jesús Molina Bravo
Subject Re: SRF written in C
Date
Msg-id 1215011940.4372.18.camel@fjmb
Whole thread Raw
In response to Re: SRF written in C  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general

El mié, 02-07-2008 a las 10:39 -0400, Alvaro Herrera escribió:
> Felipe de Jesús Molina Bravo wrote:
>
> > I suspect that my error is:
> >
> >         r = obtPadre( &intF->izq, &intF->der );
>
> You didn't show obtPadre().
>
ok it is:

        Racional* obtPadre( Racional *li, Racional *ld){
          Racional *lip;
          Racional *tr = NULL; //ap temporal, para hacer el intercambio
          bool      cont;
          int       opAnt; //operacion anterior


          lip = (Racional *) palloc(sizeof(Racional));
          tr  = (Racional *) palloc(sizeof(Racional));

          cont = true;
          opAnt = 0;
          while( cont ){

            if ( li->num > ld->num ){
                //intercambiamos li <-> ld
                 SWAP_RACIONAL(li, ld );
                 cont = false;
            }
            lip->num = ld->num - li->num;
            lip->den = ld->den - li->den;
            if ( cont ){
                 while( cont ){
                    //recorremos
                    SWAP_RACIONAL(li, ld );
                    li->num = lip->num;
                    li->den = lip->den;

                    if ( li->num > ld->num ){ //si hay intercambio ...
        continua en el ciclo
                        SWAP_RACIONAL(li, ld );
                    }else{ //si no hay intercambio
                        cont = false; //salimos del ciclo ....
                    }
                    //... pero antes de salir calculamos
                    lip->num = ld->num - li->num;
                    lip->den = ld->den - li->den;
                 }

            }
          }

          return ( lip );
        }




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg crashing
Next
From: Tom Lane
Date:
Subject: Re: pg crashing