Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ltable.h File Reference
#include "lobject.h"

Go to the source code of this file.

Macros

#define gnode(t, i)   (&(t)->node[i])
 
#define gval(n)   (&(n)->i_val)
 
#define gnext(n)   ((n)->u.next)
 
#define invalidateTMcache(t)   ((t)->flags &= ~maskflags)
 
#define isdummy(t)   ((t)->lastfree == NULL)
 
#define allocsizenode(t)   (isdummy(t) ? 0 : sizenode(t))
 
#define nodefromval(v)   cast(Node *, (v))
 

Functions

LUAI_FUNC const TValueluaH_getint (Table *t, lua_Integer key)
 
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value)
 
LUAI_FUNC const TValueluaH_getshortstr (Table *t, TString *key)
 
LUAI_FUNC const TValueluaH_getstr (Table *t, TString *key)
 
LUAI_FUNC const TValueluaH_get (Table *t, const TValue *key)
 
LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value)
 
LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, TValue *value)
 
LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)
 
LUAI_FUNC TableluaH_new (lua_State *L)
 
LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize)
 
LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize)
 
LUAI_FUNC void luaH_free (lua_State *L, Table *t)
 
LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key)
 
LUAI_FUNC lua_Unsigned luaH_getn (Table *t)
 
LUAI_FUNC unsigned int luaH_realasize (const Table *t)
 

Macro Definition Documentation

◆ allocsizenode

#define allocsizenode ( t)    (isdummy(t) ? 0 : sizenode(t))

Definition at line 31 of file lua-5.4.3/src/ltable.h.

◆ gnext

#define gnext ( n)    ((n)->u.next)

Definition at line 15 of file lua-5.4.3/src/ltable.h.

◆ gnode

#define gnode ( t,
i )   (&(t)->node[i])

Definition at line 13 of file lua-5.4.3/src/ltable.h.

◆ gval

#define gval ( n)    (&(n)->i_val)

Definition at line 14 of file lua-5.4.3/src/ltable.h.

◆ invalidateTMcache

#define invalidateTMcache ( t)    ((t)->flags &= ~maskflags)

Definition at line 23 of file lua-5.4.3/src/ltable.h.

◆ isdummy

#define isdummy ( t)    ((t)->lastfree == NULL)

Definition at line 27 of file lua-5.4.3/src/ltable.h.

◆ nodefromval

#define nodefromval ( v)    cast(Node *, (v))

Definition at line 35 of file lua-5.4.3/src/ltable.h.

Referenced by findindex(), and luaX_newstring().

Function Documentation

◆ luaH_finishset()

LUAI_FUNC void luaH_finishset ( lua_State * L,
Table * t,
const TValue * key,
const TValue * slot,
TValue * value )

Definition at line 800 of file lua-5.4.3/src/ltable.c.

801 {
802 if (isabstkey(slot))
803 luaH_newkey(L, t, key, value);
804 else
805 setobj2t(L, cast(TValue *, slot), value);
806}
int value
Definition lsqlite3.c:2155
#define cast(t, exp)
#define setobj2t
#define isabstkey(v)
void luaH_newkey(lua_State *L, Table *t, const TValue *key, TValue *value)

References cast, isabstkey, luaH_newkey(), setobj2t, and value.

Referenced by addk(), luaH_set(), luaV_finishset(), and luaX_newstring().

◆ luaH_free()

LUAI_FUNC void luaH_free ( lua_State * L,
Table * t )

Definition at line 374 of file lua-5.1.5/src/ltable.c.

374 {
375 if (t->node != dummynode)
376 luaM_freearray(L, t->node, sizenode(t), Node);
378 luaM_free(L, t);
379}
#define luaM_freearray(L, b, n, t)
#define luaM_free(L, b)
#define sizenode(t)
#define dummynode

References Table::array, cast, dummynode, freehash(), isdummy, luaH_realasize(), luaM_free, luaM_freearray, Table::node, Table::sizearray, and sizenode.

Referenced by freeobj(), freeobj(), freeobj(), and freeobj().

◆ luaH_get()

LUAI_FUNC const TValue * luaH_get ( Table * t,
const TValue * key )

Definition at line 469 of file lua-5.1.5/src/ltable.c.

469 {
470 switch (ttype(key)) {
471 case LUA_TNIL: return luaO_nilobject;
472 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
473 case LUA_TNUMBER: {
474 int k;
475 lua_Number n = nvalue(key);
476 lua_number2int(k, n);
477 if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */
478 return luaH_getnum(t, k); /* use specialized version */
479 /* else go through */
480 }
481 default: {
482 Node *n = mainposition(t, key);
483 do { /* check whether `key' is somewhere in the chain */
484 if (luaO_rawequalObj(key2tval(n), key))
485 return gval(n); /* that's it */
486 else n = gnext(n);
487 } while (n);
488 return luaO_nilobject;
489 }
490 }
491}
#define cast_num(i)
int luaO_rawequalObj(const TValue *t1, const TValue *t2)
#define nvalue(o)
#define luaO_nilobject
#define rawtsvalue(o)
#define ttype(o)
const TValue * luaH_getnum(Table *t, int key)
const TValue * luaH_getstr(Table *t, TString *key)
static Node * mainposition(const Table *t, const TValue *key)
#define gnext(n)
#define gval(n)
#define key2tval(n)
#define LUA_TSTRING
#define LUA_TNUMBER
#define LUA_TNIL
LUA_NUMBER lua_Number
#define lua_number2int(i, d)
#define luai_numeq(a, b)

References absentkey, cast_num, F2Ieq, fltvalue, getgeneric(), getgeneric(), gkey, gnext, gval, ivalue, key2tval, lua_number2int, LUA_TNIL, LUA_TNUMBER, LUA_TNUMFLT, LUA_TNUMINT, LUA_TSHRSTR, LUA_TSTRING, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, luaH_getint(), luaH_getint(), luaH_getnum(), luaH_getshortstr(), luaH_getstr(), luai_numeq, luaO_nilobject, luaO_rawequalObj(), luaV_flttointeger(), luaV_rawequalobj, luaV_tointeger(), mainposition(), mainposition(), nvalue, rawtsvalue, tsvalue, ttype, and ttypetag.

Referenced by addk(), lua_gettable(), lua_rawget(), lua_rawgetp(), lua_settable(), luaH_set(), luaH_set(), luaV_execute(), luaV_finishget(), luaV_finishset(), luaV_finishset(), luaV_gettable(), and luaV_settable().

◆ luaH_getint()

LUAI_FUNC const TValue * luaH_getint ( Table * t,
lua_Integer key )

Definition at line 516 of file lua-5.3.6/src/ltable.c.

516 {
517 /* (1 <= key && key <= t->sizearray) */
518 if (l_castS2U(key) - 1 < t->sizearray)
519 return &t->array[key - 1];
520 else {
521 Node *n = hashint(t, key);
522 for (;;) { /* check whether 'key' is somewhere in the chain */
523 if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)
524 return gval(n); /* that's it */
525 else {
526 int nx = gnext(n);
527 if (nx == 0) break;
528 n += nx;
529 }
530 }
531 return luaO_nilobject;
532 }
533}
#define gkey(n)
#define l_castS2U(i)
#define ttisinteger(o)
#define ivalue(o)
#define hashint(t, i)

References absentkey, Table::alimit, Table::array, cast_uint, gkey, gnext, gval, hashint, ivalue, keyisinteger, keyival, l_castS2U, limitequalsasize, luaH_realasize(), luaO_nilobject, Table::sizearray, and ttisinteger.

Referenced by hash_search(), luaH_get(), luaH_getn(), luaH_setint(), and unbound_search().

◆ luaH_getn()

LUAI_FUNC lua_Unsigned luaH_getn ( Table * t)

Definition at line 560 of file lua-5.1.5/src/ltable.c.

560 {
561 unsigned int j = t->sizearray;
562 if (j > 0 && ttisnil(&t->array[j - 1])) {
563 /* there is a boundary in the array part: (binary) search for it */
564 unsigned int i = 0;
565 while (j - i > 1) {
566 unsigned int m = (i+j)/2;
567 if (ttisnil(&t->array[m - 1])) j = m;
568 else i = m;
569 }
570 return i;
571 }
572 /* else must find a boundary in hash part */
573 else if (t->node == dummynode) /* hash part is empty? */
574 return j; /* that is easy... */
575 else return unbound_search(t, j);
576}
#define ttisnil(o)
static int unbound_search(Table *t, unsigned int j)

References Table::alimit, Table::array, binsearch(), cast, dummynode, hash_search(), isdummy, isempty, ispow2, ispow2realasize(), limitequalsasize, lua_assert, luaH_getint(), luaH_realasize(), Table::node, setnorealasize, Table::sizearray, ttisnil, unbound_search(), unbound_search(), and unbound_search().

Referenced by lua_objlen(), lua_rawlen(), luaV_execute(), and luaV_objlen().

◆ luaH_getshortstr()

LUAI_FUNC const TValue * luaH_getshortstr ( Table * t,
TString * key )

Definition at line 539 of file lua-5.3.6/src/ltable.c.

539 {
540 Node *n = hashstr(t, key);
541 lua_assert(key->tt == LUA_TSHRSTR);
542 for (;;) { /* check whether 'key' is somewhere in the chain */
543 const TValue *k = gkey(n);
544 if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))
545 return gval(n); /* that's it */
546 else {
547 int nx = gnext(n);
548 if (nx == 0)
549 return luaO_nilobject; /* not found */
550 n += nx;
551 }
552 }
553}
#define lua_assert(c)
#define tsvalue(o)
#define LUA_TSHRSTR
#define ttisshrstring(o)
#define eqshrstr(a, b)
#define hashstr(t, str)

References absentkey, eqshrstr, gkey, gnext, gval, hashstr, keyisshrstr, keystrval, lua_assert, LUA_TSHRSTR, LUA_VSHRSTR, luaO_nilobject, tsvalue, and ttisshrstring.

Referenced by luaH_get(), luaH_getstr(), luaT_gettm(), luaT_gettmbyobj(), luaT_objtypename(), and luaV_execute().

◆ luaH_getstr()

LUAI_FUNC const TValue * luaH_getstr ( Table * t,
TString * key )

Definition at line 455 of file lua-5.1.5/src/ltable.c.

455 {
456 Node *n = hashstr(t, key);
457 do { /* check whether `key' is somewhere in the chain */
458 if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
459 return gval(n); /* that's it */
460 else n = gnext(n);
461 } while (n);
462 return luaO_nilobject;
463}
#define ttisstring(o)
#define hashstr(t, str)

References cast, eqshrstr, getgeneric(), getgeneric(), gkey, gnext, gval, hashstr, lua_assert, LUA_TSHRSTR, LUA_VSHRSTR, luaH_getshortstr(), luaO_nilobject, NULL, rawtsvalue, setsvalue, TString::tsv, ttisshrstring, and ttisstring.

Referenced by auxgetstr(), auxgetstr(), auxsetstr(), auxsetstr(), luaH_get(), luaH_setstr(), luaT_gettm(), luaT_gettmbyobj(), luaV_execute(), luaV_execute(), and luaX_newstring().

◆ luaH_new()

LUAI_FUNC Table * luaH_new ( lua_State * L)

Definition at line 368 of file lua-5.2.4/src/ltable.c.

368 {
369 Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
370 t->metatable = NULL;
371 t->flags = cast_byte(~0);
372 t->array = NULL;
373 t->sizearray = 0;
374 setnodevector(L, t, 0);
375 return t;
376}
#define NULL
Definition gmacros.h:924
#define cast_byte(i)
#define LUA_TTABLE
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
static void setnodevector(lua_State *L, Table *t, int size)
struct Table * metatable
struct Table h

References Table::alimit, Table::array, cast_byte, Table::flags, gco2t, GCObject::h, LUA_TTABLE, LUA_VTABLE, luaC_newobj(), maskflags, Table::metatable, NULL, setnodevector(), setnodevector(), setnodevector(), and Table::sizearray.

◆ luaH_newkey()

LUAI_FUNC void luaH_newkey ( lua_State * L,
Table * t,
const TValue * key,
TValue * value )

Definition at line 654 of file lua-5.4.3/src/ltable.c.

654 {
655 Node *mp;
656 TValue aux;
657 if (l_unlikely(ttisnil(key)))
658 luaG_runerror(L, "table index is nil");
659 else if (ttisfloat(key)) {
660 lua_Number f = fltvalue(key);
661 lua_Integer k;
662 if (luaV_flttointeger(f, &k, F2Ieq)) { /* does key fit in an integer? */
663 setivalue(&aux, k);
664 key = &aux; /* insert it as an integer */
665 }
666 else if (l_unlikely(luai_numisnan(f)))
667 luaG_runerror(L, "table index is NaN");
668 }
669 if (ttisnil(value))
670 return; /* do not insert nil values */
671 mp = mainpositionTV(t, key);
672 if (!isempty(gval(mp)) || isdummy(t)) { /* main position is taken? */
673 Node *othern;
674 Node *f = getfreepos(t); /* get a free place */
675 if (f == NULL) { /* cannot find a free place? */
676 rehash(L, t, key); /* grow table */
677 /* whatever called 'newkey' takes care of TM cache */
678 luaH_set(L, t, key, value); /* insert key into grown table */
679 return;
680 }
681 lua_assert(!isdummy(t));
682 othern = mainposition(t, keytt(mp), &keyval(mp));
683 if (othern != mp) { /* is colliding node out of its main position? */
684 /* yes; move colliding node into free position */
685 while (othern + gnext(othern) != mp) /* find previous */
686 othern += gnext(othern);
687 gnext(othern) = cast_int(f - othern); /* rechain to point to 'f' */
688 *f = *mp; /* copy colliding node into free pos. (mp->next also goes) */
689 if (gnext(mp) != 0) {
690 gnext(f) += cast_int(mp - f); /* correct 'next' */
691 gnext(mp) = 0; /* now 'mp' is free */
692 }
693 setempty(gval(mp));
694 }
695 else { /* colliding node is in its own main position */
696 /* new node will go into free position */
697 if (gnext(mp) != 0)
698 gnext(f) = cast_int((mp + gnext(mp)) - f); /* chain new position */
699 else lua_assert(gnext(f) == 0);
700 gnext(mp) = cast_int(f - mp);
701 mp = f;
702 }
703 }
704 setnodekey(L, mp, key);
705 luaC_barrierback(L, obj2gco(t), key);
706 lua_assert(isempty(gval(mp)));
707 setobj2t(L, gval(mp), value);
708}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define cast_int(i)
#define obj2gco(v)
LUA_INTEGER lua_Integer
#define luaC_barrierback(L, p, v)
#define isdummy(n)
#define luai_numisnan(a)
#define setnodekey(L, key, obj)
#define fltvalue(o)
#define ttisfloat(o)
#define setivalue(obj, x)
#define setempty(v)
#define isempty(v)
#define keyval(node)
#define keytt(node)
static Node * mainpositionTV(const Table *t, const TValue *key)
void luaH_set(lua_State *L, Table *t, const TValue *key, TValue *value)
static Node * getfreepos(Table *t)
static Node * mainposition(const Table *t, int ktt, const Value *kvl)
static void rehash(lua_State *L, Table *t, const TValue *ek)
int luaV_flttointeger(lua_Number n, lua_Integer *p, F2Imod mode)
@ F2Ieq

References cast_int, F2Ieq, fltvalue, getfreepos(), gnext, gval, isdummy, isempty, keytt, keyval, lua_assert, luaC_barrierback, luaG_runerror(), luaH_set(), luai_numisnan, luaV_flttointeger(), mainposition(), mainpositionTV(), NULL, obj2gco, rehash(), setempty, setivalue, setnodekey, setobj2t, ttisfloat, ttisnil, and value.

Referenced by luaH_finishset(), and luaH_setint().

◆ luaH_next()

LUAI_FUNC int luaH_next ( lua_State * L,
Table * t,
StkId key )

Definition at line 162 of file lua-5.1.5/src/ltable.c.

162 {
163 int i = findindex(L, t, key); /* find original element */
164 for (i++; i < t->sizearray; i++) { /* try first array part */
165 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
166 setnvalue(key, cast_num(i+1));
167 setobj2s(L, key+1, &t->array[i]);
168 return 1;
169 }
170 }
171 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
172 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
173 setobj2s(L, key, key2tval(gnode(t, i)));
174 setobj2s(L, key+1, gval(gnode(t, i)));
175 return 1;
176 }
177 }
178 return 0; /* no more elements */
179}
#define setobj2s
#define setnvalue(obj, x)
static int findindex(lua_State *L, Table *t, StkId key)
#define gnode(t, i)

References Table::array, cast_int, cast_num, findindex(), findindex(), findindex(), findindex(), getnodekey, gkey, gnode, gval, isempty, key2tval, luaH_realasize(), s2v, setivalue, setnvalue, setobj2s, Table::sizearray, sizenode, and ttisnil.

Referenced by lua_next().

◆ luaH_realasize()

LUAI_FUNC unsigned int luaH_realasize ( const Table * t)

Definition at line 241 of file lua-5.4.3/src/ltable.c.

241 {
242 if (limitequalsasize(t))
243 return t->alimit; /* this is the size */
244 else {
245 unsigned int size = t->alimit;
246 /* compute the smallest power of 2 not smaller than 'n' */
247 size |= (size >> 1);
248 size |= (size >> 2);
249 size |= (size >> 4);
250 size |= (size >> 8);
251 size |= (size >> 16);
252#if (UINT_MAX >> 30) > 3
253 size |= (size >> 32); /* unsigned int has more than 32 bits */
254#endif
255 size++;
256 lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size);
257 return size;
258 }
259}
#define ispow2(x)
#define limitequalsasize(t)
unsigned int alimit

References Table::alimit, ispow2, limitequalsasize, and lua_assert.

Referenced by clearbyvalues(), luaH_free(), luaH_getint(), luaH_getn(), luaH_next(), luaV_execute(), setlimittosize(), traverseephemeron(), and traversestrongtable().

◆ luaH_resize()

LUAI_FUNC void luaH_resize ( lua_State * L,
Table * t,
unsigned int nasize,
unsigned int nhsize )

Definition at line 347 of file lua-5.3.6/src/ltable.c.

348 {
349 unsigned int i;
350 int j;
351 AuxsetnodeT asn;
352 unsigned int oldasize = t->sizearray;
353 int oldhsize = allocsizenode(t);
354 Node *nold = t->node; /* save old hash ... */
355 if (nasize > oldasize) /* array part must grow? */
356 setarrayvector(L, t, nasize);
357 /* create new hash part with appropriate size */
358 asn.t = t; asn.nhsize = nhsize;
359 if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */
360 setarrayvector(L, t, oldasize); /* array back to its original size */
361 luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */
362 }
363 if (nasize < oldasize) { /* array part must shrink? */
364 t->sizearray = nasize;
365 /* re-insert elements from vanishing slice */
366 for (i=nasize; i<oldasize; i++) {
367 if (!ttisnil(&t->array[i]))
368 luaH_setint(L, t, i + 1, &t->array[i]);
369 }
370 /* shrink array */
371 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
372 }
373 /* re-insert elements from hash part */
374 for (j = oldhsize - 1; j >= 0; j--) {
375 Node *old = nold + j;
376 if (!ttisnil(gval(old))) {
377 /* doesn't need barrier/invalidate cache, as entry was
378 already present in the table */
379 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
380 }
381 }
382 if (oldhsize > 0) /* not the dummy node? */
383 luaM_freearray(L, nold, cast(size_t, oldhsize)); /* free old hash */
384}
void luaD_throw(lua_State *L, int errcode)
int luaD_rawrunprotected(lua_State *L, Pfunc f, void *ud)
#define luaM_reallocvector(L, v, oldn, n, t)
#define setobjt2t
#define LUA_ERRMEM
#define LUA_OK
static void setarrayvector(lua_State *L, Table *t, unsigned int size)
void luaH_setint(lua_State *L, Table *t, lua_Integer key, TValue *value)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
static void auxsetnode(lua_State *L, void *ud)
#define allocsizenode(t)
unsigned int nhsize

References Table::alimit, allocsizenode, Table::array, auxsetnode(), cast, exchangehashpart(), freehash(), gkey, gval, isempty, LUA_ERRMEM, LUA_OK, luaD_rawrunprotected(), luaD_throw(), luaH_set(), luaH_setint(), luaM_error, luaM_freearray, luaM_reallocvector, AuxsetnodeT::nhsize, Table::node, NULL, reinsert(), setarrayvector(), setempty, setlimittosize(), setnodevector(), setobjt2t, Table::sizearray, AuxsetnodeT::t, and ttisnil.

Referenced by luaH_resizearray(), rehash(), and rehash().

◆ luaH_resizearray()

LUAI_FUNC void luaH_resizearray ( lua_State * L,
Table * t,
unsigned int nasize )

Definition at line 387 of file lua-5.3.6/src/ltable.c.

387 {
388 int nsize = allocsizenode(t);
389 luaH_resize(L, t, nasize, nsize);
390}
void luaH_resize(lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize)

References allocsizenode, luaH_resize(), and luaH_resize().

◆ luaH_set()

LUAI_FUNC void luaH_set ( lua_State * L,
Table * t,
const TValue * key,
TValue * value )

Definition at line 813 of file lua-5.4.3/src/ltable.c.

813 {
814 const TValue *slot = luaH_get(t, key);
815 luaH_finishset(L, t, key, slot, value);
816}
const TValue * luaH_get(Table *t, const TValue *key)
void luaH_finishset(lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)

References luaH_finishset(), luaH_get(), and value.

Referenced by luaH_newkey(), and reinsert().

◆ luaH_setint()

LUAI_FUNC void luaH_setint ( lua_State * L,
Table * t,
lua_Integer key,
TValue * value )

Definition at line 618 of file lua-5.3.6/src/ltable.c.

618 {
619 const TValue *p = luaH_getint(t, key);
620 TValue *cell;
621 if (p != luaO_nilobject)
622 cell = cast(TValue *, p);
623 else {
624 TValue k;
625 setivalue(&k, key);
626 cell = luaH_newkey(L, t, &k);
627 }
628 setobj2t(L, cell, value);
629}
TValue * luaH_newkey(lua_State *L, Table *t, const TValue *key)
const TValue * luaH_getint(Table *t, lua_Integer key)

References cast, isabstkey, luaH_getint(), luaH_newkey(), luaH_newkey(), luaO_nilobject, setivalue, setobj2t, and value.

Referenced by luaH_resize(), and luaH_resize().