Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ltable.c File Reference
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lvm.h"

Go to the source code of this file.

Macros

#define ltable_c
 
#define LUA_CORE
 
#define MAXBITS   (LUAI_BITSINT-2)
 
#define MAXASIZE   (1 << MAXBITS)
 
#define hashpow2(t, n)   (gnode(t, lmod((n), sizenode(t))))
 
#define hashstr(t, str)   hashpow2(t, (str)->tsv.hash)
 
#define hashboolean(t, p)   hashpow2(t, p)
 
#define hashmod(t, n)   (gnode(t, ((n) % ((sizenode(t)-1)|1))))
 
#define hashpointer(t, p)   hashmod(t, IntPoint(p))
 
#define dummynode   (&dummynode_)
 
#define isdummy(n)   ((n) == dummynode)
 

Functions

static Nodehashnum (const Table *t, lua_Number n)
 
static Nodemainposition (const Table *t, const TValue *key)
 
static int arrayindex (const TValue *key)
 
static int findindex (lua_State *L, Table *t, StkId key)
 
int luaH_next (lua_State *L, Table *t, StkId key)
 
static int computesizes (int nums[], int *narray)
 
static int countint (const TValue *key, int *nums)
 
static int numusearray (const Table *t, int *nums)
 
static int numusehash (const Table *t, int *nums, int *pnasize)
 
static void setarrayvector (lua_State *L, Table *t, int size)
 
static void setnodevector (lua_State *L, Table *t, int size)
 
void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize)
 
void luaH_resizearray (lua_State *L, Table *t, int nasize)
 
static void rehash (lua_State *L, Table *t, const TValue *ek)
 
TableluaH_new (lua_State *L)
 
void luaH_free (lua_State *L, Table *t)
 
static Nodegetfreepos (Table *t)
 
TValueluaH_newkey (lua_State *L, Table *t, const TValue *key)
 
const TValueluaH_getint (Table *t, int key)
 
const TValueluaH_getstr (Table *t, TString *key)
 
const TValueluaH_get (Table *t, const TValue *key)
 
TValueluaH_set (lua_State *L, Table *t, const TValue *key)
 
void luaH_setint (lua_State *L, Table *t, int key, TValue *value)
 
static int unbound_search (Table *t, unsigned int j)
 
int luaH_getn (Table *t)
 

Variables

static const Node dummynode_
 

Macro Definition Documentation

◆ dummynode

#define dummynode   (&dummynode_)

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

Referenced by setnodevector().

◆ hashboolean

#define hashboolean ( t,
p )   hashpow2(t, p)

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

Referenced by mainposition().

◆ hashmod

#define hashmod ( t,
n )   (gnode(t, ((n) % ((sizenode(t)-1)|1))))

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

Referenced by hashnum().

◆ hashpointer

#define hashpointer ( t,
p )   hashmod(t, IntPoint(p))

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

Referenced by mainposition().

◆ hashpow2

#define hashpow2 ( t,
n )   (gnode(t, lmod((n), sizenode(t))))

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

◆ hashstr

#define hashstr ( t,
str )   hashpow2(t, (str)->tsv.hash)

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

Referenced by luaH_getstr(), and mainposition().

◆ isdummy

#define isdummy ( n)    ((n) == dummynode)

◆ ltable_c

#define ltable_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ MAXASIZE

#define MAXASIZE   (1 << MAXBITS)

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

Referenced by countint().

◆ MAXBITS

#define MAXBITS   (LUAI_BITSINT-2)

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

Referenced by numusearray(), rehash(), and setnodevector().

Function Documentation

◆ arrayindex()

static int arrayindex ( const TValue * key)
static

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

127 {
128 if (ttisnumber(key)) {
129 lua_Number n = nvalue(key);
130 int k;
131 lua_number2int(k, n);
132 if (luai_numeq(cast_num(k), n))
133 return k;
134 }
135 return -1; /* `key' did not match some condition */
136}
#define cast_num(i)
#define nvalue(o)
#define ttisnumber(o)
LUA_NUMBER lua_Number
#define lua_number2int(i, d)
#define luai_numeq(a, b)

References cast_num, lua_number2int, luai_numeq, nvalue, and ttisnumber.

Referenced by countint(), and findindex().

◆ computesizes()

static int computesizes ( int nums[],
int * narray )
static

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

196 {
197 int i;
198 int twotoi; /* 2^i */
199 int a = 0; /* number of elements smaller than 2^i */
200 int na = 0; /* number of elements to go to array part */
201 int n = 0; /* optimal size for array part */
202 for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
203 if (nums[i] > 0) {
204 a += nums[i];
205 if (a > twotoi/2) { /* more than half elements present? */
206 n = twotoi; /* optimal size (till now) */
207 na = a; /* all elements smaller than n will go to array part */
208 }
209 }
210 if (a == *narray) break; /* all elements already counted */
211 }
212 *narray = n;
213 lua_assert(*narray/2 <= na && na <= *narray);
214 return na;
215}
#define lua_assert(c)

References lua_assert.

Referenced by rehash().

◆ countint()

static int countint ( const TValue * key,
int * nums )
static

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

218 {
219 int k = arrayindex(key);
220 if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
221 nums[luaO_ceillog2(k)]++; /* count as such */
222 return 1;
223 }
224 else
225 return 0;
226}
int luaO_ceillog2(unsigned int x)
static int arrayindex(const TValue *key)
#define MAXASIZE

References arrayindex(), luaO_ceillog2(), and MAXASIZE.

Referenced by numusehash(), and rehash().

◆ findindex()

static int findindex ( lua_State * L,
Table * t,
StkId key )
static

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

144 {
145 int i;
146 if (ttisnil(key)) return -1; /* first iteration */
147 i = arrayindex(key);
148 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
149 return i-1; /* yes; that's the index (corrected to C) */
150 else {
151 Node *n = mainposition(t, key);
152 for (;;) { /* check whether `key' is somewhere in the chain */
153 /* key may be dead already, but it is ok to use it in `next' */
154 if (luaV_rawequalobj(gkey(n), key) ||
155 (ttisdeadkey(gkey(n)) && iscollectable(key) &&
156 deadvalue(gkey(n)) == gcvalue(key))) {
157 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
158 /* hash elements are numbered after array ones */
159 return i + t->sizearray;
160 }
161 else n = gnext(n);
162 if (n == NULL)
163 luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
164 }
165 }
166}
#define NULL
Definition gmacros.h:924
void luaG_runerror(lua_State *L, const char *fmt,...)
#define cast_int(i)
#define gcvalue(o)
#define ttisnil(o)
#define iscollectable(o)
#define gnode(t, i)
#define gnext(n)
#define gkey(n)
#define LUA_QL(x)
#define ttisdeadkey(o)
#define deadvalue(o)
static Node * mainposition(const Table *t, const TValue *key)
#define luaV_rawequalobj(o1, o2)

References arrayindex(), cast_int, deadvalue, gcvalue, gkey, gnext, gnode, iscollectable, LUA_QL, luaG_runerror(), luaV_rawequalobj, mainposition(), NULL, Table::sizearray, ttisdeadkey, and ttisnil.

Referenced by luaH_next().

◆ getfreepos()

static Node * getfreepos ( Table * t)
static

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

387 {
388 while (t->lastfree > t->node) {
389 t->lastfree--;
390 if (ttisnil(gkey(t->lastfree)))
391 return t->lastfree;
392 }
393 return NULL; /* could not find a free place */
394}

References gkey, Table::lastfree, Table::node, NULL, and ttisnil.

Referenced by luaH_newkey().

◆ hashnum()

static Node * hashnum ( const Table * t,
lua_Number n )
static

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

80 {
81 int i;
82 luai_hashnum(i, n);
83 if (i < 0) {
84 if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
85 i = 0; /* handle INT_MIN */
86 i = -i; /* must be a positive value */
87 }
88 return hashmod(t, i);
89}
#define cast(t, exp)
#define luai_hashnum(i, n)
#define hashmod(t, n)

References cast, hashmod, and luai_hashnum.

Referenced by luaH_getint(), and mainposition().

◆ luaH_free()

void luaH_free ( lua_State * L,
Table * t )

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

379 {
380 if (!isdummy(t->node))
381 luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
382 luaM_freearray(L, t->array, t->sizearray);
383 luaM_free(L, t);
384}
#define luaM_freearray(L, b, n, t)
#define luaM_free(L, b)
#define sizenode(t)
#define isdummy(n)

References Table::array, cast, isdummy, luaM_free, luaM_freearray, Table::node, Table::sizearray, and sizenode.

◆ luaH_get()

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

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

481 {
482 switch (ttype(key)) {
483 case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key));
484 case LUA_TNIL: return luaO_nilobject;
485 case LUA_TNUMBER: {
486 int k;
487 lua_Number n = nvalue(key);
488 lua_number2int(k, n);
489 if (luai_numeq(cast_num(k), n)) /* index is int? */
490 return luaH_getint(t, k); /* use specialized version */
491 /* else go through */
492 }
493 default: {
494 Node *n = mainposition(t, key);
495 do { /* check whether `key' is somewhere in the chain */
496 if (luaV_rawequalobj(gkey(n), key))
497 return gval(n); /* that's it */
498 else n = gnext(n);
499 } while (n);
500 return luaO_nilobject;
501 }
502 }
503}
#define luaO_nilobject
#define rawtsvalue(o)
#define ttype(o)
#define gval(n)
#define LUA_TNUMBER
#define LUA_TNIL
#define LUA_TSHRSTR
const TValue * luaH_getstr(Table *t, TString *key)
const TValue * luaH_getint(Table *t, int key)

References cast_num, gkey, gnext, gval, lua_number2int, LUA_TNIL, LUA_TNUMBER, LUA_TSHRSTR, luaH_getint(), luaH_getstr(), luai_numeq, luaO_nilobject, luaV_rawequalobj, mainposition(), nvalue, rawtsvalue, and ttype.

Referenced by luaH_set().

◆ luaH_getint()

const TValue * luaH_getint ( Table * t,
int key )

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

446 {
447 /* (1 <= key && key <= t->sizearray) */
448 if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
449 return &t->array[key-1];
450 else {
451 lua_Number nk = cast_num(key);
452 Node *n = hashnum(t, nk);
453 do { /* check whether `key' is somewhere in the chain */
454 if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
455 return gval(n); /* that's it */
456 else n = gnext(n);
457 } while (n);
458 return luaO_nilobject;
459 }
460}
static Node * hashnum(const Table *t, lua_Number n)

References Table::array, cast, cast_num, gkey, gnext, gval, hashnum(), luai_numeq, luaO_nilobject, nvalue, Table::sizearray, and ttisnumber.

Referenced by lua_getglobal(), lua_getglobal(), lua_geti(), lua_load(), lua_rawgeti(), lua_rawgeti(), lua_setglobal(), lua_setglobal(), lua_seti(), luaH_get(), luaH_setint(), and unbound_search().

◆ luaH_getn()

int luaH_getn ( Table * t)

Definition at line 560 of file lua-5.2.4/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 (isdummy(t->node)) /* hash part is empty? */
574 return j; /* that is easy... */
575 else return unbound_search(t, j);
576}
static int unbound_search(Table *t, unsigned int j)

References Table::array, isdummy, Table::node, Table::sizearray, ttisnil, and unbound_search().

◆ luaH_getstr()

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

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

466 {
467 Node *n = hashstr(t, key);
468 lua_assert(key->tsv.tt == LUA_TSHRSTR);
469 do { /* check whether `key' is somewhere in the chain */
470 if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
471 return gval(n); /* that's it */
472 else n = gnext(n);
473 } while (n);
474 return luaO_nilobject;
475}
#define ttisshrstring(o)
#define eqshrstr(a, b)
#define hashstr(t, str)
struct TString::@46 tsv

References eqshrstr, gkey, gnext, gval, hashstr, lua_assert, LUA_TSHRSTR, luaO_nilobject, rawtsvalue, TString::tsv, and ttisshrstring.

Referenced by luaH_get().

◆ luaH_new()

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 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::array, cast_byte, Table::flags, GCObject::h, LUA_TTABLE, luaC_newobj(), Table::metatable, NULL, setnodevector(), and Table::sizearray.

◆ luaH_newkey()

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

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

405 {
406 Node *mp;
407 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
408 else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
409 luaG_runerror(L, "table index is NaN");
410 mp = mainposition(t, key);
411 if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
412 Node *othern;
413 Node *n = getfreepos(t); /* get a free place */
414 if (n == NULL) { /* cannot find a free place? */
415 rehash(L, t, key); /* grow table */
416 /* whatever called 'newkey' take care of TM cache and GC barrier */
417 return luaH_set(L, t, key); /* insert key into grown table */
418 }
419 lua_assert(!isdummy(n));
420 othern = mainposition(t, gkey(mp));
421 if (othern != mp) { /* is colliding node out of its main position? */
422 /* yes; move colliding node into free position */
423 while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
424 gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
425 *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
426 gnext(mp) = NULL; /* now `mp' is free */
427 setnilvalue(gval(mp));
428 }
429 else { /* colliding node is in its own main position */
430 /* new node will go into free position */
431 gnext(n) = gnext(mp); /* chain new position */
432 gnext(mp) = n;
433 mp = n;
434 }
435 }
436 setobj2t(L, gkey(mp), key);
437 luaC_barrierback(L, obj2gco(t), key);
438 lua_assert(ttisnil(gval(mp)));
439 return gval(mp);
440}
#define setnilvalue(obj)
#define setobj2t
#define obj2gco(v)
#define luaC_barrierback(L, p, v)
static Node * getfreepos(Table *t)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
static void rehash(lua_State *L, Table *t, const TValue *ek)
#define luai_numisnan(a)

References getfreepos(), gkey, gnext, gval, isdummy, lua_assert, luaC_barrierback, luaG_runerror(), luaH_set(), luai_numisnan, mainposition(), NULL, nvalue, obj2gco, rehash(), setnilvalue, setobj2t, ttisnil, and ttisnumber.

Referenced by luaH_set(), luaH_setint(), luaV_finishset(), and luaV_settable().

◆ luaH_next()

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

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

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

References Table::array, cast_num, findindex(), gkey, gnode, gval, setnvalue, setobj2s, Table::sizearray, sizenode, and ttisnil.

◆ luaH_resize()

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

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

304 {
305 int i;
306 int oldasize = t->sizearray;
307 int oldhsize = t->lsizenode;
308 Node *nold = t->node; /* save old hash ... */
309 if (nasize > oldasize) /* array part must grow? */
310 setarrayvector(L, t, nasize);
311 /* create new hash part with appropriate size */
312 setnodevector(L, t, nhsize);
313 if (nasize < oldasize) { /* array part must shrink? */
314 t->sizearray = nasize;
315 /* re-insert elements from vanishing slice */
316 for (i=nasize; i<oldasize; i++) {
317 if (!ttisnil(&t->array[i]))
318 luaH_setint(L, t, i + 1, &t->array[i]);
319 }
320 /* shrink array */
321 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
322 }
323 /* re-insert elements from hash part */
324 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
325 Node *old = nold+i;
326 if (!ttisnil(gval(old))) {
327 /* doesn't need barrier/invalidate cache, as entry was
328 already present in the table */
329 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
330 }
331 }
332 if (!isdummy(nold))
333 luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
334}
#define luaM_reallocvector(L, v, oldn, n, t)
#define setobjt2t
#define twoto(x)
static void setarrayvector(lua_State *L, Table *t, int size)
void luaH_setint(lua_State *L, Table *t, int key, TValue *value)

References Table::array, cast, gkey, gval, isdummy, Table::lsizenode, luaH_set(), luaH_setint(), luaM_freearray, luaM_reallocvector, Table::node, setarrayvector(), setnodevector(), setobjt2t, Table::sizearray, ttisnil, and twoto.

Referenced by init_registry(), init_registry(), init_registry(), lua_createtable(), luaH_resizearray(), luaV_execute(), luaV_execute(), and rehash().

◆ luaH_resizearray()

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

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

337 {
338 int nsize = isdummy(t->node) ? 0 : sizenode(t);
339 luaH_resize(L, t, nasize, nsize);
340}
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)

References isdummy, luaH_resize(), Table::node, and sizenode.

◆ luaH_set()

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

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

510 {
511 const TValue *p = luaH_get(t, key);
512 if (p != luaO_nilobject)
513 return cast(TValue *, p);
514 else return luaH_newkey(L, t, key);
515}
const TValue * luaH_get(Table *t, const TValue *key)
TValue * luaH_newkey(lua_State *L, Table *t, const TValue *key)

References cast, luaH_get(), luaH_newkey(), and luaO_nilobject.

Referenced by luaH_newkey(), and luaH_resize().

◆ luaH_setint()

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

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

518 {
519 const TValue *p = luaH_getint(t, key);
520 TValue *cell;
521 if (p != luaO_nilobject)
522 cell = cast(TValue *, p);
523 else {
524 TValue k;
525 setnvalue(&k, cast_num(key));
526 cell = luaH_newkey(L, t, &k);
527 }
528 setobj2t(L, cell, value);
529}
int value
Definition lsqlite3.c:2155

References cast, cast_num, luaH_getint(), luaH_newkey(), luaO_nilobject, setnvalue, setobj2t, and value.

Referenced by collectvalidlines(), collectvalidlines(), collectvalidlines(), init_registry(), init_registry(), lua_rawseti(), lua_rawseti(), luaH_resize(), and luaV_execute().

◆ mainposition()

static Node * mainposition ( const Table * t,
const TValue * key )
static

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

97 {
98 switch (ttype(key)) {
99 case LUA_TNUMBER:
100 return hashnum(t, nvalue(key));
101 case LUA_TLNGSTR: {
102 TString *s = rawtsvalue(key);
103 if (s->tsv.extra == 0) { /* no hash? */
104 s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash);
105 s->tsv.extra = 1; /* now it has its hash */
106 }
107 return hashstr(t, rawtsvalue(key));
108 }
109 case LUA_TSHRSTR:
110 return hashstr(t, rawtsvalue(key));
111 case LUA_TBOOLEAN:
112 return hashboolean(t, bvalue(key));
114 return hashpointer(t, pvalue(key));
115 case LUA_TLCF:
116 return hashpointer(t, fvalue(key));
117 default:
118 return hashpointer(t, gcvalue(key));
119 }
120}
#define pvalue(o)
#define bvalue(o)
#define getstr(ts)
#define LUA_TBOOLEAN
#define LUA_TLIGHTUSERDATA
#define fvalue(o)
#define LUA_TLNGSTR
#define LUA_TLCF
unsigned int luaS_hash(const char *str, size_t l, unsigned int seed)
#define hashboolean(t, p)
#define hashpointer(t, p)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References bvalue, fvalue, gcvalue, getstr, hashboolean, hashnum(), hashpointer, hashstr, LUA_TBOOLEAN, LUA_TLCF, LUA_TLIGHTUSERDATA, LUA_TLNGSTR, LUA_TNUMBER, LUA_TSHRSTR, luaS_hash(), nvalue, pvalue, rawtsvalue, s, and ttype.

Referenced by findindex(), luaH_get(), and luaH_newkey().

◆ numusearray()

static int numusearray ( const Table * t,
int * nums )
static

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

229 {
230 int lg;
231 int ttlg; /* 2^lg */
232 int ause = 0; /* summation of `nums' */
233 int i = 1; /* count to traverse all array keys */
234 for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
235 int lc = 0; /* counter */
236 int lim = ttlg;
237 if (lim > t->sizearray) {
238 lim = t->sizearray; /* adjust upper limit */
239 if (i > lim)
240 break; /* no more elements to count */
241 }
242 /* count elements in range (2^(lg-1), 2^lg] */
243 for (; i <= lim; i++) {
244 if (!ttisnil(&t->array[i-1]))
245 lc++;
246 }
247 nums[lg] += lc;
248 ause += lc;
249 }
250 return ause;
251}
#define MAXBITS

References Table::array, MAXBITS, Table::sizearray, and ttisnil.

Referenced by rehash().

◆ numusehash()

static int numusehash ( const Table * t,
int * nums,
int * pnasize )
static

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

254 {
255 int totaluse = 0; /* total number of elements */
256 int ause = 0; /* summation of `nums' */
257 int i = sizenode(t);
258 while (i--) {
259 Node *n = &t->node[i];
260 if (!ttisnil(gval(n))) {
261 ause += countint(gkey(n), nums);
262 totaluse++;
263 }
264 }
265 *pnasize += ause;
266 return totaluse;
267}
static int countint(const TValue *key, int *nums)

References countint(), gkey, gval, Table::node, sizenode, and ttisnil.

Referenced by rehash().

◆ rehash()

static void rehash ( lua_State * L,
Table * t,
const TValue * ek )
static

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

343 {
344 int nasize, na;
345 int nums[MAXBITS+1]; /* nums[i] = number of keys with 2^(i-1) < k <= 2^i */
346 int i;
347 int totaluse;
348 for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */
349 nasize = numusearray(t, nums); /* count keys in array part */
350 totaluse = nasize; /* all those keys are integer keys */
351 totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
352 /* count extra key */
353 nasize += countint(ek, nums);
354 totaluse++;
355 /* compute new size for array part */
356 na = computesizes(nums, &nasize);
357 /* resize the table to new computed sizes */
358 luaH_resize(L, t, nasize, totaluse - na);
359}
static int computesizes(int nums[], int *narray)
static int numusearray(const Table *t, int *nums)
static int numusehash(const Table *t, int *nums, int *pnasize)

References computesizes(), countint(), luaH_resize(), MAXBITS, numusearray(), and numusehash().

Referenced by luaH_newkey().

◆ setarrayvector()

static void setarrayvector ( lua_State * L,
Table * t,
int size )
static

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

270 {
271 int i;
272 luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
273 for (i=t->sizearray; i<size; i++)
274 setnilvalue(&t->array[i]);
275 t->sizearray = size;
276}

References Table::array, luaM_reallocvector, setnilvalue, and Table::sizearray.

Referenced by luaH_resize().

◆ setnodevector()

static void setnodevector ( lua_State * L,
Table * t,
int size )
static

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

279 {
280 int lsize;
281 if (size == 0) { /* no elements to hash part? */
282 t->node = cast(Node *, dummynode); /* use common `dummynode' */
283 lsize = 0;
284 }
285 else {
286 int i;
287 lsize = luaO_ceillog2(size);
288 if (lsize > MAXBITS)
289 luaG_runerror(L, "table overflow");
290 size = twoto(lsize);
291 t->node = luaM_newvector(L, size, Node);
292 for (i=0; i<size; i++) {
293 Node *n = gnode(t, i);
294 gnext(n) = NULL;
295 setnilvalue(gkey(n));
296 setnilvalue(gval(n));
297 }
298 }
299 t->lsizenode = cast_byte(lsize);
300 t->lastfree = gnode(t, size); /* all positions are free */
301}
#define luaM_newvector(L, n, t)
#define dummynode

References cast, cast_byte, dummynode, gkey, gnext, gnode, gval, Table::lastfree, Table::lsizenode, luaG_runerror(), luaM_newvector, luaO_ceillog2(), MAXBITS, Table::node, NULL, setnilvalue, and twoto.

Referenced by luaH_new(), and luaH_resize().

◆ unbound_search()

static int unbound_search ( Table * t,
unsigned int j )
static

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

532 {
533 unsigned int i = j; /* i is zero or a present index */
534 j++;
535 /* find `i' and `j' such that i is present and j is not */
536 while (!ttisnil(luaH_getint(t, j))) {
537 i = j;
538 j *= 2;
539 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
540 /* table was built with bad purposes: resort to linear search */
541 i = 1;
542 while (!ttisnil(luaH_getint(t, i))) i++;
543 return i - 1;
544 }
545 }
546 /* now do a binary search between them */
547 while (j - i > 1) {
548 unsigned int m = (i+j)/2;
549 if (ttisnil(luaH_getint(t, m))) j = m;
550 else i = m;
551 }
552 return i;
553}
#define MAX_INT

References cast, luaH_getint(), MAX_INT, and ttisnil.

Referenced by luaH_getn().

Variable Documentation

◆ dummynode_

const Node dummynode_
static
Initial value:
= {
}
#define NILCONSTANT

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

71 {
72 {NILCONSTANT}, /* value */
73 {{NILCONSTANT, NULL}} /* key */
74};