bridge/class-master/depend/pari/src/basemath/bibli2.c
/********************************************************************/
/**                      SEARCH IN SORTED VECTOR                   **/
/********************************************************************/
/* index of x in table T, 0 otherwise */
SEARCH IN SORTED VECTOR
index of x in table T, 0 otherwise
SEARCH IN SORTED VECTOR index of x in table T 0 otherwise
long
tablesearch(GEN T, GEN x, int (*cmp)(GEN,GEN))
{
  long l = 1, u = lg(T)-1, i, s;
  while (u>=l)
  {
    i = (l+u)>>1; s = cmp(x, gel(T,i));
    if (!s) return i;
    if (s<0) u=i-1; else l=i+1;
  }
  return 0;
}
long tablesearch ( GEN T , GEN x , int ( * cmp ) ( GEN , GEN ) ) { long l = 1 , u = lg ( T ) - 1 , i , s ; while ( u >= l ) { i = ( l + u ) >> 1 ; s = cmp ( x , gel ( T , i ) ) ; if ( ! s ) return i ; if ( s < 0 ) u = i - 1 ; else l = i + 1 ; } return 0 ; }
SEARCH IN SORTED VECTOR
index of x in table T, 0 otherwise
SEARCH IN SORTED VECTOR index of x in table T 0 otherwise