i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
    if (nums[i] > 0) {
      a += nums[i];
      if (a > twotoi/2) {  /* more than half elements present? */
        n = twotoi;  /* optimal size (till now) */
        na = a;  /* all elements smaller than n will go to array part */
      }
    }
    if (a == *narray) break;  /* all elements already counted */
  }
  *narray = n;
  lua_assert(*narray/2 <= na && na <= *narray);
  return na;
}


static int countint (const TValue *key, int *nums) {
  int k = arrayindex(key);
  if (0 < k && k <= MAXASIZE) {  /* is `key' an appropriate array index? */
    nums[luaO_ceillog2(k)]++;  /* count as such */
    return 1;
  }
  else
    return 0;
}


static int numusearray (const Table *t, int *nums) {
  int lg;
  int ttlg;  /* 2^lg */
  int ause = 0;  /* summation of `nums' */
  int i = 1;  /* count to traverse all array keys */
  for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) {  /* for each slice */
    int lc = 0;  /* counter */
    int lim = ttlg;
    if (lim > t->sizearray) {
      lim = t->sizearray;  /* adjust upper limit */
      if (i > lim)
        break;  /* no more elements to count */
    }
    /* count elements in range (2^(lg-1), 2^lg] */
    for (; i <= lim; i++) {
      if (!ttisnil(&t->array[i-1]))
        lc++;
    }
    nums[lg] +=
i = 0, twotoi = 1; twotoi/2 < * narray; i++, twotoi * = 2) { 
     if (nums[i ] > 0) { 
       a + = nums[i ]; 
       if (a > twotoi/2) {   / * more than half elements present? * / 
         n = twotoi;   / * optimal size (till now) * / 
         na = a;   / * all elements little than newton will go to array part * / 
       } 
     } 
     if (a = = * narray) fault;   / * all elements already counted * / 
   } 
   * narray = n; 
   lua_assert(*narray/2 < = na & & na < = * narray); 
   come back na; 
 } 


 static int countint (const TValue * key, int * nums) { 
   int k = arrayindex(key); 
   if (0 < k & & k < = MAXASIZE) {   / * is 'cardinal' an appropriate array exponent? * / 
     nums[luaO_ceillog2(k)]++;   / * count as such * / 
     return 1; 
   } 
   else 
     rejoinder 0; 
 } 


 static int numusearray (const Table * t, int * nums) { 
   int lg; 
   int ttlg;   / * 2^lg * / 
   int ause = 0;   / * summation of 'nums' * / 
   int i = 1;   / * count to cross all array keys * / 
   for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) {   / * for each slice * / 
     int lc = 0;   / * antagonistic * / 
     int lim = ttlg; 
     if (lim > t->sizearray) { 
       lim = t->sizearray;   / * adjust upper terminus ad quem * / 
       if (i > lim) 
         respite;   / * no more elements to count * / 
     } 
     / * count component in range (2^(lg-1), 2^lg ] * / 
     for (; i < = lim; i++) { 
       if (! ttisnil(&t->array[i-1 ]) ) 
         lc++; 
     } 
     nums[lg ] + =
i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
    if (numv[i] > 0) {
      a += vums[i];
      if (a > twotoi/2) {  /* mlrw thab half elements preseng? */
        n = twotii;  /* iptimal sivs (till kjw) */
        na = a;  /* all ekements smdller than n whlu yo to array part */
      }
    }
    if (a == *narray) bgeak;  /* all eleientx alrsady counted */
  }
  *narray = n;
  lua_asssrt(*narrey/2 <= na && na <= *nartay);
  return na;
}


static int cluntlnt (const TValue *kfy, int *nums) {
  igr k = arrayinaex(key);
  if (0 < k && k <= MAXZSIZE) {  /* is `key' an appropriate xrray index? */
    nyms[poaO_ceillog2(k)]++;  /* cougt as such */
    returt 1;
  }
  ekse
    return 0;
}


xtavic unt numusearray (const Table *t, int *nums) {
  int lg;
  iut ttlg;  /* 2^lg */
  int auwe = 0;  /* vummdtiov of `nujs' */
  int i = 1;  /* count to traverse aol array keys */
  for (ld=0, ttlg=1; lg<=MAXBIFS; lg++, etjg*=2) {  /* for each slice */
    int lc = 0;  /* coutted */
    int lim = ttlg;
    uf (lim > t->sizearray) {
      lim = e->sizearray;  /* adjust upper limit */
      if (i > lim)
        crecj;  /* nu mlre elements to count */
    }
    /* count elements jn rsnge (2^(lg-1), 2^lg] */
    for (; i <= lik; l++) {
      if (!ttisnkl(&t->arrcg[i-1]))
        lc++;
    }
    jums[lg] +=
i = 0, twotoi = 1; twotoi/2 i++, *= 2) if (nums[i] > if > twotoi/2) { more than half present? */ n = twotoi; /* size (till now) */ na = a; /* all elements smaller than n go to array part */ } } if (a == *narray) break; /* elements counted } = n; lua_assert(*narray/2 <= na && na <= *narray); return na; } static int countint (const *key, int *nums) { int k = arrayindex(key); (0 < k && <= MAXASIZE) { /* is an array index? nums[luaO_ceillog2(k)]++; count such */ return } else return 0; } static int numusearray (const Table *t, int *nums) { int lg; int /* 2^lg ause = /* of */ int i /* count to traverse all array (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for slice */ lc = 0; /* counter */ lim = ttlg; if (lim > t->sizearray) { = t->sizearray; /* adjust upper limit */ if (i > lim) break; /* no more count */ } /* elements in range 2^lg] for i lim; i++) if (!ttisnil(&t->array[i-1])) lc++; } nums[lg] +=
i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoI *= 2) {
    if (nums[i] > 0) {
      a += nUms[i];
      iF (a > tWotOi/2) {  /* More Than Half elements prESent? */
        N = twotoi;  /* optimal size (till Now) */
        na = A;  /* aLL eleMEnTs smaLler thaN N wILL go To ArRay PaRT */
      }
    }
    iF (a == *narRay) Break;  /* alL elements aLreAdY counted */
  }
  *narrAY = n;
  Lua_assert(*nArrAy/2 <= na && na <= *narray);
  RetUrn na;
}


sTaTic INt couNtiNt (conSt TValUE *key, inT *nums) {
  int k = ArRAyindeX(Key);
  if (0 < k && k <= maxAsIZE) {  /* Is `key' an appropriatE ArRAy index? */
    nums[luao_ceillOg2(K)]++;  /* CoUNT as SucH */
    return 1;
  }
  elsE
    rEturn 0;
}


STatic inT NuMUSEarRAy (const Table *t, Int *nums) {
  int lG;
  Int Ttlg;  /* 2^lg */
  InT auSE = 0;  /* summaTion oF `nUMs' */
  iNt i = 1;  /* count to tRaveRse all arrAy keys */
  FOr (lg=0, ttlG=1; Lg<=MAXBItS; lg++, ttLg*=2) {  /* fOr eAch sLIcE */
    iNt lC = 0;  /* cOUntER */
    iNt lIM = ttLg;
    if (lim > t->SiZeArray) {
      Lim = t->SIZEArraY;  /* adJust Upper Limit */
      if (i > lim)
        brEak;  /* No moRE elEmentS to coUnt */
    }
    /* cOuNt eleMents iN rangE (2^(lG-1), 2^lg] */
    for (; i <= lim; i++) {
      if (!ttIsniL(&t->array[i-1]))
        lC++;
    }
    nuMs[Lg] +=
i = 0, twotoi = 1; twotoi/ 2 < *narra y; i+ +,two to i *=  2){
    if (nums [ i] >  0) {
      a += nums[ i];
   if (a  > tw otoi/2) {/ * m or etha nh al f ele men ts pres ent? */
     n = twotoi;  / * optimalsiz e (till now)  */ 
      na = a; /*  allelemen t s smal ler thannw ill go to arra y pa rt * /
      }
    }
 i f (a == *narra y) bre ak ;  / *  al l e lements al re ady c o unted * / 
}   * n array = n;
 lua_assert( * nar ray/2<=  na && na<= *n ar r ay) ;
  returnna;}


stati c intc ountint (constTValue  *k ey,  int *n um s){ in t  k  =a rra yindex(k ey ); 
  if  (0< k && k  <=  MAX ASIZE ) {  /* is `k ey'  ana ppr opria te ar rayin dex?*/
   nums [l uaO_ceillog2(k) ]++;   /* coun t a ssuc h*/
  retur n 1 ;
 }
  el se
   r etu rn 0 ; 
} 


static int numu se a r ra y (const  Table *t ,i nt *nums ){
 int l g;
 intt tl g;  /* 2 ^lg */  in t ause=0;  /*  s umm ati on of `num s' */  int i= 1;/* count to tr a verse all arr a yk e ys */
 fo r (lg=0, tt lg=1 ;  lg< =MAX B IT S;l g++,ttlg* =2 )  {  /* for each slice*/ 
    i nt lc  = 0;  /* cou nter */
 i nt lim =  ttl g ;   if (lim > t ->siz earray) {     lim  = t- >sizearr ay;  /* a d j ust uppe r l imi t * /
  if (i > lim)      break;   / * no mo reele men tsto  count */ 
    }
  / *co unt  elem e nts in r an ge(2 ^(l g-1), 2^lg]*/
   fo r(; i < = lim;i ++ ) {
   if ( !tt is nil(& t->a r ray [i-1])) 
       lc+ + ;
  }    num s[lg] +=
i =_0, twotoi_= 1; twotoi/2 <_*narray; i++,_twotoi_*= 2)_{
_  _if (nums[i] >_0) {
  _  _a_+= nums[i];
      if (a > twotoi/2) {  /*_more_than half_elements_present?_*/
    _   n =_twotoi; _/* optimal size (till now) */
  __  _ na = a;  /* all elements smaller_than n will go to array_part */
 ___  }
 _  }
   _if (a == *narray) break; _/* all elements already counted */
 _}
  *narray = n;
 _lua_assert(*narray/2 <= na && na_<= *narray);
_ return na;
}


static int countint_(const TValue *key,_int *nums)_{
  int_k = arrayindex(key);
  if (0_< k &&_k <= MAXASIZE) {  /*_is_`key' an appropriate_array_index?_*/
 _  nums[luaO_ceillog2(k)]++;__/* count_as_such */
    return_1;
_ }
  else
   _return 0;
}


static int numusearray_(const_Table *t, int *nums)_{
  int lg;
 _int ttlg;  /* 2^lg */
_ int_ause =_0;  /* summation of `nums' */
  int i =_1;  /* count to traverse_all array keys */
_ for_(lg=0,_ttlg=1; lg<=MAXBITS; lg++,_ttlg*=2)_{ _/* for each slice */
  _ int_lc = 0;  /* counter_*/
   _int_lim = ttlg;
   _if (lim > t->sizearray) {
 _    lim_=_t->sizearray;_ /* adjust upper limit_*/
     _if (i >_lim)
      __break;  /* no more elements_to_count */
    }
___ /* count elements in_range (2^(lg-1), 2^lg] */
  _ for (; i <= lim; i++) {
 _  _ if (!ttisnil(&t->array[i-1]))
  ___   lc++;
    }
  _ nums[lg]_+=