Lines Matching refs:t
75 #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) argument
81 #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) argument
84 #define hashstr(t,str) hashpow2(t, (str)->hash) argument
85 #define hashboolean(t,p) hashpow2(t, p) argument
88 #define hashpointer(t,p) hashmod(t, point2uint(p)) argument
108 static Node *hashint (const Table *t, lua_Integer i) { in hashint() argument
111 return hashmod(t, cast_int(ui)); in hashint()
113 return hashmod(t, ui); in hashint()
151 static Node *mainpositionTV (const Table *t, const TValue *key) { in mainpositionTV() argument
155 return hashint(t, i); in mainpositionTV()
159 return hashmod(t, l_hashfloat(n)); in mainpositionTV()
163 return hashstr(t, ts); in mainpositionTV()
167 return hashpow2(t, luaS_hashlongstr(ts)); in mainpositionTV()
170 return hashboolean(t, 0); in mainpositionTV()
172 return hashboolean(t, 1); in mainpositionTV()
175 return hashpointer(t, p); in mainpositionTV()
179 return hashpointer(t, f); in mainpositionTV()
183 return hashpointer(t, o); in mainpositionTV()
189 l_sinline Node *mainpositionfromnode (const Table *t, Node *nd) { in mainpositionfromnode() argument
192 return mainpositionTV(t, &key); in mainpositionfromnode()
244 #define limitequalsasize(t) (isrealasize(t) || ispow2((t)->alimit)) argument
250 LUAI_FUNC unsigned int luaH_realasize (const Table *t) { in luaH_realasize() argument
251 if (limitequalsasize(t)) in luaH_realasize()
252 return t->alimit; /* this is the size */ in luaH_realasize()
254 unsigned int size = t->alimit; in luaH_realasize()
267 lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size); in luaH_realasize()
278 static int ispow2realasize (const Table *t) { in ispow2realasize() argument
279 return (!isrealasize(t) || ispow2(t->alimit)); in ispow2realasize()
283 static unsigned int setlimittosize (Table *t) { in setlimittosize() argument
284 t->alimit = luaH_realasize(t); in setlimittosize()
285 setrealasize(t); in setlimittosize()
286 return t->alimit; in setlimittosize()
290 #define limitasasize(t) check_exp(isrealasize(t), t->alimit) argument
299 static const TValue *getgeneric (Table *t, const TValue *key, int deadok) { in getgeneric() argument
300 Node *n = mainpositionTV(t, key); in getgeneric()
331 static unsigned int findindex (lua_State *L, Table *t, TValue *key, in findindex() argument
339 const TValue *n = getgeneric(t, key, 1); in findindex()
342 i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ in findindex()
349 int luaH_next (lua_State *L, Table *t, StkId key) { in luaH_next() argument
350 unsigned int asize = luaH_realasize(t); in luaH_next()
351 unsigned int i = findindex(L, t, s2v(key), asize); /* find original key */ in luaH_next()
353 if (!isempty(&t->array[i])) { /* a non-empty entry? */ in luaH_next()
355 setobj2s(L, key + 1, &t->array[i]); in luaH_next()
359 for (i -= asize; cast_int(i) < sizenode(t); i++) { /* hash part */ in luaH_next()
360 if (!isempty(gval(gnode(t, i)))) { /* a non-empty entry? */ in luaH_next()
361 Node *n = gnode(t, i); in luaH_next()
371 static void freehash (lua_State *L, Table *t) { in freehash() argument
372 if (!isdummy(t)) in freehash()
373 luaM_freearray(L, t->node, cast_sizet(sizenode(t))); in freehash()
429 static unsigned int numusearray (const Table *t, unsigned int *nums) { in numusearray() argument
434 unsigned int asize = limitasasize(t); /* real array size */ in numusearray()
446 if (!isempty(&t->array[i-1])) in numusearray()
456 static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) { in numusehash() argument
459 int i = sizenode(t); in numusehash()
461 Node *n = &t->node[i]; in numusehash()
480 static void setnodevector (lua_State *L, Table *t, unsigned int size) { in setnodevector() argument
482 t->node = cast(Node *, dummynode); /* use common 'dummynode' */ in setnodevector()
483 t->lsizenode = 0; in setnodevector()
484 t->lastfree = NULL; /* signal that it is using dummy node */ in setnodevector()
492 t->node = luaM_newvector(L, size, Node); in setnodevector()
494 Node *n = gnode(t, i); in setnodevector()
499 t->lsizenode = cast_byte(lsize); in setnodevector()
500 t->lastfree = gnode(t, size); /* all positions are free */ in setnodevector()
508 static void reinsert (lua_State *L, Table *ot, Table *t) { in reinsert() argument
518 luaH_set(L, t, &k, gval(old)); in reinsert()
553 void luaH_resize (lua_State *L, Table *t, unsigned int newasize, in luaH_resize() argument
557 unsigned int oldasize = setlimittosize(t); in luaH_resize()
562 t->alimit = newasize; /* pretend array has new size... */ in luaH_resize()
563 exchangehashpart(t, &newt); /* and new hash */ in luaH_resize()
566 if (!isempty(&t->array[i])) in luaH_resize()
567 luaH_setint(L, t, i + 1, &t->array[i]); in luaH_resize()
569 t->alimit = oldasize; /* restore current size... */ in luaH_resize()
570 exchangehashpart(t, &newt); /* and hash (in case of errors) */ in luaH_resize()
573 newarray = luaM_reallocvector(L, t->array, oldasize, newasize, TValue); in luaH_resize()
579 exchangehashpart(t, &newt); /* 't' has the new hash ('newt' has the old) */ in luaH_resize()
580 t->array = newarray; /* set new array part */ in luaH_resize()
581 t->alimit = newasize; in luaH_resize()
583 setempty(&t->array[i]); in luaH_resize()
585 reinsert(L, &newt, t); /* 'newt' now has the old hash */ in luaH_resize()
590 void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) { in luaH_resizearray() argument
591 int nsize = allocsizenode(t); in luaH_resizearray()
592 luaH_resize(L, t, nasize, nsize); in luaH_resizearray()
598 static void rehash (lua_State *L, Table *t, const TValue *ek) { in rehash() argument
605 setlimittosize(t); in rehash()
606 na = numusearray(t, nums); /* count keys in array part */ in rehash()
608 totaluse += numusehash(t, nums, &na); /* count keys in hash part */ in rehash()
616 luaH_resize(L, t, asize, totaluse - na); in rehash()
628 Table *t = gco2t(o); in luaH_new() local
629 t->metatable = NULL; in luaH_new()
630 t->flags = cast_byte(maskflags); /* table has no metamethod fields */ in luaH_new()
631 t->array = NULL; in luaH_new()
632 t->alimit = 0; in luaH_new()
633 setnodevector(L, t, 0); in luaH_new()
634 return t; in luaH_new()
638 void luaH_free (lua_State *L, Table *t) { in luaH_free() argument
639 freehash(L, t); in luaH_free()
640 luaM_freearray(L, t->array, luaH_realasize(t)); in luaH_free()
641 luaM_free(L, t); in luaH_free()
645 static Node *getfreepos (Table *t) { in getfreepos() argument
646 if (!isdummy(t)) { in getfreepos()
647 while (t->lastfree > t->node) { in getfreepos()
648 t->lastfree--; in getfreepos()
649 if (keyisnil(t->lastfree)) in getfreepos()
650 return t->lastfree; in getfreepos()
665 void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) { in luaH_newkey() argument
682 mp = mainpositionTV(t, key); in luaH_newkey()
683 if (!isempty(gval(mp)) || isdummy(t)) { /* main position is taken? */ in luaH_newkey()
685 Node *f = getfreepos(t); /* get a free place */ in luaH_newkey()
687 rehash(L, t, key); /* grow table */ in luaH_newkey()
689 luaH_set(L, t, key, value); /* insert key into grown table */ in luaH_newkey()
692 lua_assert(!isdummy(t)); in luaH_newkey()
693 othern = mainpositionfromnode(t, mp); in luaH_newkey()
716 luaC_barrierback(L, obj2gco(t), key); in luaH_newkey()
730 const TValue *luaH_getint (Table *t, lua_Integer key) { in luaH_getint() argument
731 if (l_castS2U(key) - 1u < t->alimit) /* 'key' in [1, t->alimit]? */ in luaH_getint()
732 return &t->array[key - 1]; in luaH_getint()
733 else if (!limitequalsasize(t) && /* key still may be in the array part? */ in luaH_getint()
734 (l_castS2U(key) == t->alimit + 1 || in luaH_getint()
735 l_castS2U(key) - 1u < luaH_realasize(t))) { in luaH_getint()
736 t->alimit = cast_uint(key); /* probably '#t' is here now */ in luaH_getint()
737 return &t->array[key - 1]; in luaH_getint()
740 Node *n = hashint(t, key); in luaH_getint()
758 const TValue *luaH_getshortstr (Table *t, TString *key) { in luaH_getshortstr() argument
759 Node *n = hashstr(t, key); in luaH_getshortstr()
774 const TValue *luaH_getstr (Table *t, TString *key) { in luaH_getstr() argument
776 return luaH_getshortstr(t, key); in luaH_getstr()
780 return getgeneric(t, &ko, 0); in luaH_getstr()
788 const TValue *luaH_get (Table *t, const TValue *key) { in luaH_get() argument
790 case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key)); in luaH_get()
791 case LUA_VNUMINT: return luaH_getint(t, ivalue(key)); in luaH_get()
796 return luaH_getint(t, k); /* use specialized version */ in luaH_get()
800 return getgeneric(t, key, 0); in luaH_get()
811 void luaH_finishset (lua_State *L, Table *t, const TValue *key, in luaH_finishset() argument
814 luaH_newkey(L, t, key, value); in luaH_finishset()
824 void luaH_set (lua_State *L, Table *t, const TValue *key, TValue *value) { in luaH_set() argument
825 const TValue *slot = luaH_get(t, key); in luaH_set()
826 luaH_finishset(L, t, key, slot, value); in luaH_set()
830 void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) { in luaH_setint() argument
831 const TValue *p = luaH_getint(t, key); in luaH_setint()
835 luaH_newkey(L, t, &k, value); in luaH_setint()
855 static lua_Unsigned hash_search (Table *t, lua_Unsigned j) { in hash_search() argument
864 if (isempty(luaH_getint(t, j))) /* t[j] not present? */ in hash_search()
869 } while (!isempty(luaH_getint(t, j))); /* repeat until an absent t[j] */ in hash_search()
873 if (isempty(luaH_getint(t, m))) j = m; in hash_search()
923 lua_Unsigned luaH_getn (Table *t) { in luaH_getn() argument
924 unsigned int limit = t->alimit; in luaH_getn()
925 if (limit > 0 && isempty(&t->array[limit - 1])) { /* (1)? */ in luaH_getn()
927 if (limit >= 2 && !isempty(&t->array[limit - 2])) { in luaH_getn()
929 if (ispow2realasize(t) && !ispow2(limit - 1)) { in luaH_getn()
930 t->alimit = limit - 1; in luaH_getn()
931 setnorealasize(t); /* now 'alimit' is not the real size */ in luaH_getn()
936 unsigned int boundary = binsearch(t->array, 0, limit); in luaH_getn()
938 if (ispow2realasize(t) && boundary > luaH_realasize(t) / 2) { in luaH_getn()
939 t->alimit = boundary; /* use it as the new limit */ in luaH_getn()
940 setnorealasize(t); in luaH_getn()
946 if (!limitequalsasize(t)) { /* (2)? */ in luaH_getn()
948 if (isempty(&t->array[limit])) /* 'limit + 1' is empty? */ in luaH_getn()
951 limit = luaH_realasize(t); in luaH_getn()
952 if (isempty(&t->array[limit - 1])) { /* empty? */ in luaH_getn()
955 unsigned int boundary = binsearch(t->array, t->alimit, limit); in luaH_getn()
956 t->alimit = boundary; in luaH_getn()
962 lua_assert(limit == luaH_realasize(t) && in luaH_getn()
963 (limit == 0 || !isempty(&t->array[limit - 1]))); in luaH_getn()
964 if (isdummy(t) || isempty(luaH_getint(t, cast(lua_Integer, limit + 1)))) in luaH_getn()
967 return hash_search(t, limit); in luaH_getn()
976 Node *luaH_mainposition (const Table *t, const TValue *key) { in luaH_mainposition() argument
977 return mainpositionTV(t, key); in luaH_mainposition()