The Battle for Wesnoth  1.17.0-dev
Macros | Functions | Variables
ltable.cpp File Reference
#include "lprefix.h"
#include <math.h>
#include <limits.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"
Include dependency graph for ltable.cpp:

Go to the source code of this file.

Macros

#define ltable_c
 
#define LUA_CORE
 
#define MAXABITS   cast_int(sizeof(int) * CHAR_BIT - 1)
 
#define MAXASIZE   luaM_limitN(1u << MAXABITS, TValue)
 
#define MAXHBITS   (MAXABITS - 1)
 
#define MAXHSIZE   luaM_limitN(1u << MAXHBITS, Node)
 
#define hashpow2(t, n)   (gnode(t, lmod((n), sizenode(t))))
 
#define hashstr(t, str)   hashpow2(t, (str)->hash)
 
#define hashboolean(t, p)   hashpow2(t, p)
 
#define hashint(t, i)   hashpow2(t, i)
 
#define hashmod(t, n)   (gnode(t, ((n) % ((sizenode(t)-1)|1))))
 
#define hashpointer(t, p)   hashmod(t, point2uint(p))
 
#define dummynode   (&dummynode_)
 
#define limitequalsasize(t)   (isrealasize(t) || ispow2((t)->alimit))
 
#define limitasasize(t)   check_exp(isrealasize(t), t->alimit)
 

Functions

static int l_hashfloat (lua_Number n)
 
static Nodemainposition (const Table *t, int ktt, const Value *kvl)
 
static NodemainpositionTV (const Table *t, const TValue *key)
 
static int equalkey (const TValue *k1, const Node *n2, int deadok)
 
LUAI_FUNC unsigned int luaH_realasize (const Table *t)
 
static int ispow2realasize (const Table *t)
 
static unsigned int setlimittosize (Table *t)
 
static const TValuegetgeneric (Table *t, const TValue *key, int deadok)
 
static unsigned int arrayindex (lua_Integer k)
 
static unsigned int findindex (lua_State *L, Table *t, TValue *key, unsigned int asize)
 
int luaH_next (lua_State *L, Table *t, StkId key)
 
static void freehash (lua_State *L, Table *t)
 
static unsigned int computesizes (unsigned int nums[], unsigned int *pna)
 
static int countint (lua_Integer key, unsigned int *nums)
 
static unsigned int numusearray (const Table *t, unsigned int *nums)
 
static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna)
 
static void setnodevector (lua_State *L, Table *t, unsigned int size)
 
static void reinsert (lua_State *L, Table *ot, Table *t)
 
static void exchangehashpart (Table *t1, Table *t2)
 
void luaH_resize (lua_State *L, Table *t, unsigned int newasize, unsigned int nhsize)
 
void luaH_resizearray (lua_State *L, Table *t, unsigned 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, lua_Integer key)
 
const TValueluaH_getshortstr (Table *t, TString *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, lua_Integer key, TValue *value)
 
static lua_Unsigned hash_search (Table *t, lua_Unsigned j)
 
static unsigned int binsearch (const TValue *array, unsigned int i, unsigned int j)
 
lua_Unsigned luaH_getn (Table *t)
 

Variables

static const Node dummynode_
 
static const TValue absentkey = {ABSTKEYCONSTANT}
 

Macro Definition Documentation

◆ dummynode

#define dummynode   (&dummynode_)

Definition at line 88 of file ltable.cpp.

Referenced by setnodevector().

◆ hashboolean

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

Definition at line 74 of file ltable.cpp.

Referenced by mainposition().

◆ hashint

#define hashint (   t,
  i 
)    hashpow2(t, i)

Definition at line 75 of file ltable.cpp.

Referenced by luaH_getint(), and mainposition().

◆ hashmod

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

Definition at line 82 of file ltable.cpp.

Referenced by mainposition().

◆ hashpointer

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

Definition at line 85 of file ltable.cpp.

Referenced by mainposition().

◆ hashpow2

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

Definition at line 71 of file ltable.cpp.

Referenced by mainposition().

◆ hashstr

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

Definition at line 73 of file ltable.cpp.

Referenced by luaH_getshortstr(), and mainposition().

◆ limitasasize

#define limitasasize (   t)    check_exp(isrealasize(t), t->alimit)

Definition at line 260 of file ltable.cpp.

Referenced by numusearray().

◆ limitequalsasize

#define limitequalsasize (   t)    (isrealasize(t) || ispow2((t)->alimit))

Definition at line 216 of file ltable.cpp.

Referenced by luaH_getint(), luaH_getn(), and luaH_realasize().

◆ ltable_c

#define ltable_c

Definition at line 7 of file ltable.cpp.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file ltable.cpp.

◆ MAXABITS

#define MAXABITS   cast_int(sizeof(int) * CHAR_BIT - 1)

Definition at line 46 of file ltable.cpp.

Referenced by numusearray(), and rehash().

◆ MAXASIZE

#define MAXASIZE   luaM_limitN(1u << MAXABITS, TValue)

Definition at line 54 of file ltable.cpp.

Referenced by arrayindex().

◆ MAXHBITS

#define MAXHBITS   (MAXABITS - 1)

Definition at line 60 of file ltable.cpp.

Referenced by setnodevector().

◆ MAXHSIZE

#define MAXHSIZE   luaM_limitN(1u << MAXHBITS, Node)

Definition at line 68 of file ltable.cpp.

Referenced by setnodevector().

Function Documentation

◆ arrayindex()

static unsigned int arrayindex ( lua_Integer  k)
static

Definition at line 288 of file ltable.cpp.

References cast_uint, l_castS2U, and MAXASIZE.

Referenced by countint(), and findindex().

◆ binsearch()

static unsigned int binsearch ( const TValue array,
unsigned int  i,
unsigned int  j 
)
static

Definition at line 836 of file ltable.cpp.

References i, and isempty.

Referenced by luaH_getn().

◆ computesizes()

static unsigned int computesizes ( unsigned int  nums[],
unsigned int *  pna 
)
static

Definition at line 361 of file ltable.cpp.

References a, i, and lua_assert.

Referenced by rehash().

◆ countint()

static int countint ( lua_Integer  key,
unsigned int *  nums 
)
static

Definition at line 383 of file ltable.cpp.

References arrayindex(), and luaO_ceillog2().

Referenced by numusehash(), and rehash().

◆ equalkey()

static int equalkey ( const TValue k1,
const Node n2,
int  deadok 
)
static

◆ exchangehashpart()

static void exchangehashpart ( Table t1,
Table t2 
)
static

Definition at line 497 of file ltable.cpp.

References Table::lastfree, Table::lsizenode, and Table::node.

Referenced by luaH_resize().

◆ findindex()

static unsigned int findindex ( lua_State L,
Table t,
TValue key,
unsigned int  asize 
)
static

Definition at line 301 of file ltable.cpp.

References arrayindex(), cast_int, getgeneric(), gnode, i, isabstkey, ivalue, luaG_runerror(), n, nodefromval, ttisinteger, ttisnil, and unlikely.

Referenced by luaH_next().

◆ freehash()

static void freehash ( lua_State L,
Table t 
)
static

Definition at line 341 of file ltable.cpp.

References cast_sizet, isdummy, luaM_freearray, Table::node, and sizenode.

Referenced by luaH_free(), and luaH_resize().

◆ getfreepos()

static Node* getfreepos ( Table t)
static

Definition at line 615 of file ltable.cpp.

References isdummy, keyisnil, Table::lastfree, and Table::node.

Referenced by luaH_newkey().

◆ getgeneric()

static const TValue* getgeneric ( Table t,
const TValue key,
int  deadok 
)
static

Definition at line 269 of file ltable.cpp.

References absentkey, equalkey(), gnext, gval, mainpositionTV(), and n.

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

◆ hash_search()

static lua_Unsigned hash_search ( Table t,
lua_Unsigned  j 
)
static

Definition at line 811 of file ltable.cpp.

References i, isempty, l_castS2U, and luaH_getint().

Referenced by luaH_getn().

◆ ispow2realasize()

static int ispow2realasize ( const Table t)
static

Definition at line 248 of file ltable.cpp.

References Table::alimit, ispow2, and isrealasize.

Referenced by luaH_getn().

◆ l_hashfloat()

static int l_hashfloat ( lua_Number  n)
static

Definition at line 114 of file ltable.cpp.

References cast_int, cast_num, cast_uint, i, l_mathop, lua_assert, lua_numbertointeger, luai_numisnan, and n.

Referenced by mainposition().

◆ luaH_free()

void luaH_free ( lua_State L,
Table t 
)

Definition at line 608 of file ltable.cpp.

References Table::array, freehash(), luaH_realasize(), luaM_free, and luaM_freearray.

Referenced by freeobj().

◆ luaH_get()

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

◆ luaH_getint()

const TValue* luaH_getint ( Table t,
lua_Integer  key 
)

◆ luaH_getn()

lua_Unsigned luaH_getn ( Table t)

◆ luaH_getshortstr()

const TValue* luaH_getshortstr ( Table t,
TString key 
)

◆ luaH_getstr()

const TValue* luaH_getstr ( Table t,
TString key 
)

Definition at line 741 of file ltable.cpp.

References cast, getgeneric(), LUA_VSHRSTR, luaH_getshortstr(), and setsvalue.

Referenced by auxgetstr(), auxsetstr(), and luaV_execute().

◆ luaH_new()

Table* luaH_new ( lua_State L)

◆ luaH_newkey()

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

◆ luaH_next()

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

Definition at line 319 of file ltable.cpp.

References Table::array, cast_int, findindex(), getnodekey, gnode, gval, i, isempty, luaH_realasize(), n, s2v, setivalue, setobj2s, and sizenode.

Referenced by lua_next().

◆ luaH_realasize()

LUAI_FUNC unsigned int luaH_realasize ( const Table t)

◆ luaH_resize()

void luaH_resize ( lua_State L,
Table t,
unsigned int  newasize,
unsigned int  nhsize 
)

◆ luaH_resizearray()

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

Definition at line 560 of file ltable.cpp.

References allocsizenode, and luaH_resize().

Referenced by luaV_execute().

◆ luaH_set()

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

Definition at line 776 of file ltable.cpp.

References cast, isabstkey, luaH_get(), luaH_newkey(), and p.

Referenced by addk(), aux_rawset(), luaH_newkey(), luaX_newstring(), and reinsert().

◆ luaH_setint()

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

◆ mainposition()

static Node* mainposition ( const Table t,
int  ktt,
const Value kvl 
)
static

◆ mainpositionTV()

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

Definition at line 163 of file ltable.cpp.

References mainposition(), rawtt, and valraw.

Referenced by getgeneric(), luaH_getn(), and luaH_newkey().

◆ numusearray()

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

Definition at line 399 of file ltable.cpp.

References Table::array, i, isempty, limitasasize, and MAXABITS.

Referenced by rehash().

◆ numusehash()

static int numusehash ( const Table t,
unsigned int *  nums,
unsigned int *  pna 
)
static

Definition at line 426 of file ltable.cpp.

References countint(), gval, i, isempty, keyisinteger, keyival, n, Table::node, and sizenode.

Referenced by rehash().

◆ rehash()

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

◆ reinsert()

static void reinsert ( lua_State L,
Table ot,
Table t 
)
static

Definition at line 478 of file ltable.cpp.

References getnodekey, gnode, gval, isempty, luaH_set(), setobjt2t, utf8::size(), and sizenode.

Referenced by luaH_resize().

◆ setlimittosize()

static unsigned int setlimittosize ( Table t)
static

Definition at line 253 of file ltable.cpp.

References Table::alimit, luaH_realasize(), and setrealasize.

Referenced by luaH_resize(), and rehash().

◆ setnodevector()

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

Variable Documentation

◆ absentkey

const TValue absentkey = {ABSTKEYCONSTANT}
static

Definition at line 96 of file ltable.cpp.

Referenced by getgeneric(), luaH_get(), luaH_getint(), and luaH_getshortstr().

◆ dummynode_

const Node dummynode_
static
Initial value:
= {
{{NULL}, LUA_VEMPTY,
LUA_VNIL, 0, {NULL}}
}
#define LUA_VEMPTY
Definition: lobject.h:164
#define LUA_VNIL
Definition: lobject.h:161

Definition at line 90 of file ltable.cpp.