bridge/class-master/depend/pari/src/basemath/bibli2.c
/* looks if x belongs to the set T and returns the index if yes, 0 if no */
looks if x belongs to the set T and returns the index if yes, 0 if no
looks if x belongs to the set T and returns the index if yes 0 if no
long
gen_search(GEN T, GEN x, long flag, void *data, int (*cmp)(void*,GEN,GEN))
{
  long u = lg(T)-1, i, l, s;
  if (!u) return flag? 1: 0;
  l = 1;
  do
  {
    i = (l+u)>>1; s = cmp(data, x, gel(T,i));
    if (!s) return flag? 0: i;
    if (s<0) u=i-1; else l=i+1;
  } while (u>=l);
  if (!flag) return 0;
  return (s<0)? i: i+1;
}
long gen_search ( GEN T , GEN x , long flag , void * data , int ( * cmp ) ( void * , GEN , GEN ) ) { long u = lg ( T ) - 1 , i , l , s ; if ( ! u ) return flag ? 1 : 0 ; l = 1 ; do { i = ( l + u ) >> 1 ; s = cmp ( data , x , gel ( T , i ) ) ; if ( ! s ) return flag ? 0 : i ; if ( s < 0 ) u = i - 1 ; else l = i + 1 ; } while ( u >= l ) ; if ( ! flag ) return 0 ; return ( s < 0 ) ? i : i + 1 ; }
looks if x belongs to the set T and returns the index if yes, 0 if no
looks if x belongs to the set T and returns the index if yes 0 if no