misc/liblua/ltable.c
changeset 3697 d5b30d6373fc
parent 2812 0a24853de796
child 10017 de822cd3df3a
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    46 
    46 
    47 #define MAXASIZE	(1 << MAXBITS)
    47 #define MAXASIZE	(1 << MAXBITS)
    48 
    48 
    49 
    49 
    50 #define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))
    50 #define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))
    51   
    51 
    52 #define hashstr(t,str)  hashpow2(t, (str)->tsv.hash)
    52 #define hashstr(t,str)  hashpow2(t, (str)->tsv.hash)
    53 #define hashboolean(t,p)        hashpow2(t, p)
    53 #define hashboolean(t,p)        hashpow2(t, p)
    54 
    54 
    55 
    55 
    56 /*
    56 /*
   300   int oldhsize = t->lsizenode;
   300   int oldhsize = t->lsizenode;
   301   Node *nold = t->node;  /* save old hash ... */
   301   Node *nold = t->node;  /* save old hash ... */
   302   if (nasize > oldasize)  /* array part must grow? */
   302   if (nasize > oldasize)  /* array part must grow? */
   303     setarrayvector(L, t, nasize);
   303     setarrayvector(L, t, nasize);
   304   /* create new hash part with appropriate size */
   304   /* create new hash part with appropriate size */
   305   setnodevector(L, t, nhsize);  
   305   setnodevector(L, t, nhsize);
   306   if (nasize < oldasize) {  /* array part must shrink? */
   306   if (nasize < oldasize) {  /* array part must shrink? */
   307     t->sizearray = nasize;
   307     t->sizearray = nasize;
   308     /* re-insert elements from vanishing slice */
   308     /* re-insert elements from vanishing slice */
   309     for (i=nasize; i<oldasize; i++) {
   309     for (i=nasize; i<oldasize; i++) {
   310       if (!ttisnil(&t->array[i]))
   310       if (!ttisnil(&t->array[i]))
   388 }
   388 }
   389 
   389 
   390 
   390 
   391 
   391 
   392 /*
   392 /*
   393 ** inserts a new key into a hash table; first, check whether key's main 
   393 ** inserts a new key into a hash table; first, check whether key's main
   394 ** position is free. If not, check whether colliding node is in its main 
   394 ** position is free. If not, check whether colliding node is in its main
   395 ** position or not: if it is not, move colliding node to an empty place and 
   395 ** position or not: if it is not, move colliding node to an empty place and
   396 ** put new key in its main position; otherwise (colliding node is in its main 
   396 ** put new key in its main position; otherwise (colliding node is in its main
   397 ** position), new key goes to an empty position. 
   397 ** position), new key goes to an empty position.
   398 */
   398 */
   399 static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
   399 static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
   400   Node *mp = mainposition(t, key);
   400   Node *mp = mainposition(t, key);
   401   if (!ttisnil(gval(mp)) || mp == dummynode) {
   401   if (!ttisnil(gval(mp)) || mp == dummynode) {
   402     Node *othern;
   402     Node *othern;