ltable.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. ** $Id: ltable.c,v 2.99 2014/11/02 19:19:04 roberto Exp roberto $
  3. ** Lua tables (hash)
  4. ** See Copyright Notice in lua.h
  5. */
  6. #define ltable_c
  7. #define LUA_CORE
  8. #include "lprefix.h"
  9. /*
  10. ** Implementation of tables (aka arrays, objects, or hash tables).
  11. ** Tables keep its elements in two parts: an array part and a hash part.
  12. ** Non-negative integer keys are all candidates to be kept in the array
  13. ** part. The actual size of the array is the largest 'n' such that at
  14. ** least half the slots between 0 and n are in use.
  15. ** Hash uses a mix of chained scatter table with Brent's variation.
  16. ** A main invariant of these tables is that, if an element is not
  17. ** in its main position (i.e. the 'original' position that its hash gives
  18. ** to it), then the colliding element is in its own main position.
  19. ** Hence even when the load factor reaches 100%, performance remains good.
  20. */
  21. #include <float.h>
  22. #include <math.h>
  23. #include <string.h>
  24. #include <limits.h>
  25. #include "lua.h"
  26. #include "ldebug.h"
  27. #include "ldo.h"
  28. #include "lgc.h"
  29. #include "lmem.h"
  30. #include "lobject.h"
  31. #include "lstate.h"
  32. #include "lstring.h"
  33. #include "ltable.h"
  34. #include "lvm.h"
  35. /*
  36. ** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is
  37. ** the largest integer such that MAXASIZE fits in an unsigned int.
  38. */
  39. #define MAXABITS cast_int(sizeof(int) * CHAR_BIT - 1)
  40. #define MAXASIZE (1u << MAXABITS)
  41. /*
  42. ** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest
  43. ** integer such that 2^MAXHBITS fits in a signed int. (Note that the
  44. ** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still
  45. ** fits comfortably in an unsigned int.)
  46. */
  47. #define MAXHBITS (MAXABITS - 1)
  48. #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
  49. #define hashstr(t,str) hashpow2(t, (str)->hash)
  50. #define hashboolean(t,p) hashpow2(t, p)
  51. #define hashint(t,i) hashpow2(t, i)
  52. /*
  53. ** for some types, it is better to avoid modulus by power of 2, as
  54. ** they tend to have many 2 factors.
  55. */
  56. #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
  57. #define hashpointer(t,p) hashmod(t, point2int(p))
  58. #define dummynode (&dummynode_)
  59. #define isdummy(n) ((n) == dummynode)
  60. static const Node dummynode_ = {
  61. {NILCONSTANT}, /* value */
  62. {{NILCONSTANT, 0}} /* key */
  63. };
  64. /*
  65. ** Checks whether a float has a value representable as a lua_Integer
  66. ** (and does the conversion if so)
  67. */
  68. static int numisinteger (lua_Number x, lua_Integer *p) {
  69. if ((x) == l_floor(x)) /* integral value? */
  70. return lua_numbertointeger(x, p); /* try as an integer */
  71. else return 0;
  72. }
  73. /*
  74. ** hash for floating-point numbers
  75. */
  76. static Node *hashfloat (const Table *t, lua_Number n) {
  77. int i;
  78. n = l_mathop(frexp)(n, &i) * cast_num(INT_MAX - DBL_MAX_EXP);
  79. i += cast_int(n);
  80. if (i < 0) {
  81. if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
  82. i = 0; /* handle INT_MIN */
  83. i = -i; /* must be a positive value */
  84. }
  85. return hashmod(t, i);
  86. }
  87. /*
  88. ** returns the 'main' position of an element in a table (that is, the index
  89. ** of its hash value)
  90. */
  91. static Node *mainposition (const Table *t, const TValue *key) {
  92. switch (ttype(key)) {
  93. case LUA_TNUMINT:
  94. return hashint(t, ivalue(key));
  95. case LUA_TNUMFLT:
  96. return hashfloat(t, fltvalue(key));
  97. case LUA_TSHRSTR:
  98. return hashstr(t, tsvalue(key));
  99. case LUA_TLNGSTR: {
  100. TString *s = tsvalue(key);
  101. if (s->extra == 0) { /* no hash? */
  102. s->hash = luaS_hash(getstr(s), s->len, s->hash);
  103. s->extra = 1; /* now it has its hash */
  104. }
  105. return hashstr(t, tsvalue(key));
  106. }
  107. case LUA_TBOOLEAN:
  108. return hashboolean(t, bvalue(key));
  109. case LUA_TLIGHTUSERDATA:
  110. return hashpointer(t, pvalue(key));
  111. case LUA_TLCF:
  112. return hashpointer(t, fvalue(key));
  113. default:
  114. return hashpointer(t, gcvalue(key));
  115. }
  116. }
  117. /*
  118. ** returns the index for 'key' if 'key' is an appropriate key to live in
  119. ** the array part of the table, 0 otherwise.
  120. */
  121. static unsigned int arrayindex (const TValue *key) {
  122. if (ttisinteger(key)) {
  123. lua_Integer k = ivalue(key);
  124. if (0 < k && (lua_Unsigned)k <= MAXASIZE)
  125. return cast(unsigned int, k); /* 'key' is an appropriate array index */
  126. }
  127. return 0; /* 'key' did not match some condition */
  128. }
  129. /*
  130. ** returns the index of a 'key' for table traversals. First goes all
  131. ** elements in the array part, then elements in the hash part. The
  132. ** beginning of a traversal is signaled by 0.
  133. */
  134. static unsigned int findindex (lua_State *L, Table *t, StkId key) {
  135. unsigned int i;
  136. if (ttisnil(key)) return 0; /* first iteration */
  137. i = arrayindex(key);
  138. if (i != 0 && i <= t->sizearray) /* is 'key' inside array part? */
  139. return i; /* yes; that's the index */
  140. else {
  141. int nx;
  142. Node *n = mainposition(t, key);
  143. for (;;) { /* check whether 'key' is somewhere in the chain */
  144. /* key may be dead already, but it is ok to use it in 'next' */
  145. if (luaV_rawequalobj(gkey(n), key) ||
  146. (ttisdeadkey(gkey(n)) && iscollectable(key) &&
  147. deadvalue(gkey(n)) == gcvalue(key))) {
  148. i = cast_int(n - gnode(t, 0)); /* key index in hash table */
  149. /* hash elements are numbered after array ones */
  150. return (i + 1) + t->sizearray;
  151. }
  152. nx = gnext(n);
  153. if (nx == 0)
  154. luaG_runerror(L, "invalid key to 'next'"); /* key not found */
  155. else n += nx;
  156. }
  157. }
  158. }
  159. int luaH_next (lua_State *L, Table *t, StkId key) {
  160. unsigned int i = findindex(L, t, key); /* find original element */
  161. for (; i < t->sizearray; i++) { /* try first array part */
  162. if (!ttisnil(&t->array[i])) { /* a non-nil value? */
  163. setivalue(key, i + 1);
  164. setobj2s(L, key+1, &t->array[i]);
  165. return 1;
  166. }
  167. }
  168. for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) { /* hash part */
  169. if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
  170. setobj2s(L, key, gkey(gnode(t, i)));
  171. setobj2s(L, key+1, gval(gnode(t, i)));
  172. return 1;
  173. }
  174. }
  175. return 0; /* no more elements */
  176. }
  177. /*
  178. ** {=============================================================
  179. ** Rehash
  180. ** ==============================================================
  181. */
  182. /*
  183. ** Compute the optimal size for the array part of table 't'. 'nums' is a
  184. ** "count array" where 'nums[i]' is the number of integers in the table
  185. ** between 2^(i - 1) + 1 and 2^i. Put in '*narray' the optimal size, and
  186. ** return the number of elements that will go to that part.
  187. */
  188. static unsigned int computesizes (unsigned int nums[], unsigned int *narray) {
  189. int i;
  190. unsigned int twotoi; /* 2^i */
  191. unsigned int a = 0; /* number of elements smaller than 2^i */
  192. unsigned int na = 0; /* number of elements to go to array part */
  193. unsigned int n = 0; /* optimal size for array part */
  194. for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
  195. if (nums[i] > 0) {
  196. a += nums[i];
  197. if (a > twotoi/2) { /* more than half elements present? */
  198. n = twotoi; /* optimal size (till now) */
  199. na = a; /* all elements up to 'n' will go to array part */
  200. }
  201. }
  202. if (a == *narray) break; /* all elements already counted */
  203. }
  204. *narray = n;
  205. lua_assert(*narray/2 <= na && na <= *narray);
  206. return na;
  207. }
  208. static int countint (const TValue *key, unsigned int *nums) {
  209. unsigned int k = arrayindex(key);
  210. if (k != 0) { /* is 'key' an appropriate array index? */
  211. nums[luaO_ceillog2(k)]++; /* count as such */
  212. return 1;
  213. }
  214. else
  215. return 0;
  216. }
  217. static unsigned int numusearray (const Table *t, unsigned int *nums) {
  218. int lg;
  219. unsigned int ttlg; /* 2^lg */
  220. unsigned int ause = 0; /* summation of 'nums' */
  221. unsigned int i = 1; /* count to traverse all array keys */
  222. /* traverse each slice */
  223. for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {
  224. unsigned int lc = 0; /* counter */
  225. unsigned int lim = ttlg;
  226. if (lim > t->sizearray) {
  227. lim = t->sizearray; /* adjust upper limit */
  228. if (i > lim)
  229. break; /* no more elements to count */
  230. }
  231. /* count elements in range (2^(lg - 1), 2^lg] */
  232. for (; i <= lim; i++) {
  233. if (!ttisnil(&t->array[i-1]))
  234. lc++;
  235. }
  236. nums[lg] += lc;
  237. ause += lc;
  238. }
  239. return ause;
  240. }
  241. static int numusehash (const Table *t, unsigned int *nums,
  242. unsigned int *pnasize) {
  243. int totaluse = 0; /* total number of elements */
  244. int ause = 0; /* elements added to 'nums' (can go to array part) */
  245. int i = sizenode(t);
  246. while (i--) {
  247. Node *n = &t->node[i];
  248. if (!ttisnil(gval(n))) {
  249. ause += countint(gkey(n), nums);
  250. totaluse++;
  251. }
  252. }
  253. *pnasize += ause;
  254. return totaluse;
  255. }
  256. static void setarrayvector (lua_State *L, Table *t, unsigned int size) {
  257. unsigned int i;
  258. luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
  259. for (i=t->sizearray; i<size; i++)
  260. setnilvalue(&t->array[i]);
  261. t->sizearray = size;
  262. }
  263. static void setnodevector (lua_State *L, Table *t, unsigned int size) {
  264. int lsize;
  265. if (size == 0) { /* no elements to hash part? */
  266. t->node = cast(Node *, dummynode); /* use common 'dummynode' */
  267. lsize = 0;
  268. }
  269. else {
  270. int i;
  271. lsize = luaO_ceillog2(size);
  272. if (lsize > MAXHBITS)
  273. luaG_runerror(L, "table overflow");
  274. size = twoto(lsize);
  275. t->node = luaM_newvector(L, size, Node);
  276. for (i = 0; i < (int)size; i++) {
  277. Node *n = gnode(t, i);
  278. gnext(n) = 0;
  279. setnilvalue(wgkey(n));
  280. setnilvalue(gval(n));
  281. }
  282. }
  283. t->lsizenode = cast_byte(lsize);
  284. t->lastfree = gnode(t, size); /* all positions are free */
  285. }
  286. void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
  287. unsigned int nhsize) {
  288. unsigned int i;
  289. int j;
  290. unsigned int oldasize = t->sizearray;
  291. int oldhsize = t->lsizenode;
  292. Node *nold = t->node; /* save old hash ... */
  293. if (nasize > oldasize) /* array part must grow? */
  294. setarrayvector(L, t, nasize);
  295. /* create new hash part with appropriate size */
  296. setnodevector(L, t, nhsize);
  297. if (nasize < oldasize) { /* array part must shrink? */
  298. t->sizearray = nasize;
  299. /* re-insert elements from vanishing slice */
  300. for (i=nasize; i<oldasize; i++) {
  301. if (!ttisnil(&t->array[i]))
  302. luaH_setint(L, t, i + 1, &t->array[i]);
  303. }
  304. /* shrink array */
  305. luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
  306. }
  307. /* re-insert elements from hash part */
  308. for (j = twoto(oldhsize) - 1; j >= 0; j--) {
  309. Node *old = nold + j;
  310. if (!ttisnil(gval(old))) {
  311. /* doesn't need barrier/invalidate cache, as entry was
  312. already present in the table */
  313. setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
  314. }
  315. }
  316. if (!isdummy(nold))
  317. luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
  318. }
  319. void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {
  320. int nsize = isdummy(t->node) ? 0 : sizenode(t);
  321. luaH_resize(L, t, nasize, nsize);
  322. }
  323. /*
  324. ** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i
  325. */
  326. static void rehash (lua_State *L, Table *t, const TValue *ek) {
  327. unsigned int nasize, na;
  328. unsigned int nums[MAXABITS + 1];
  329. int i;
  330. int totaluse;
  331. for (i = 0; i <= MAXABITS; i++) nums[i] = 0; /* reset counts */
  332. nasize = numusearray(t, nums); /* count keys in array part */
  333. totaluse = nasize; /* all those keys are integer keys */
  334. totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
  335. /* count extra key */
  336. nasize += countint(ek, nums);
  337. totaluse++;
  338. /* compute new size for array part */
  339. na = computesizes(nums, &nasize);
  340. /* resize the table to new computed sizes */
  341. luaH_resize(L, t, nasize, totaluse - na);
  342. }
  343. /*
  344. ** }=============================================================
  345. */
  346. Table *luaH_new (lua_State *L) {
  347. GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
  348. Table *t = gco2t(o);
  349. t->metatable = NULL;
  350. t->flags = cast_byte(~0);
  351. t->array = NULL;
  352. t->sizearray = 0;
  353. setnodevector(L, t, 0);
  354. return t;
  355. }
  356. void luaH_free (lua_State *L, Table *t) {
  357. if (!isdummy(t->node))
  358. luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
  359. luaM_freearray(L, t->array, t->sizearray);
  360. luaM_free(L, t);
  361. }
  362. static Node *getfreepos (Table *t) {
  363. while (t->lastfree > t->node) {
  364. t->lastfree--;
  365. if (ttisnil(gkey(t->lastfree)))
  366. return t->lastfree;
  367. }
  368. return NULL; /* could not find a free place */
  369. }
  370. /*
  371. ** inserts a new key into a hash table; first, check whether key's main
  372. ** position is free. If not, check whether colliding node is in its main
  373. ** position or not: if it is not, move colliding node to an empty place and
  374. ** put new key in its main position; otherwise (colliding node is in its main
  375. ** position), new key goes to an empty position.
  376. */
  377. TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
  378. Node *mp;
  379. TValue aux;
  380. if (ttisnil(key)) luaG_runerror(L, "table index is nil");
  381. else if (ttisfloat(key)) {
  382. lua_Number n = fltvalue(key);
  383. lua_Integer k;
  384. if (luai_numisnan(n))
  385. luaG_runerror(L, "table index is NaN");
  386. if (numisinteger(n, &k)) { /* index is int? */
  387. setivalue(&aux, k);
  388. key = &aux; /* insert it as an integer */
  389. }
  390. }
  391. mp = mainposition(t, key);
  392. if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
  393. Node *othern;
  394. Node *f = getfreepos(t); /* get a free place */
  395. if (f == NULL) { /* cannot find a free place? */
  396. rehash(L, t, key); /* grow table */
  397. /* whatever called 'newkey' takes care of TM cache and GC barrier */
  398. return luaH_set(L, t, key); /* insert key into grown table */
  399. }
  400. lua_assert(!isdummy(f));
  401. othern = mainposition(t, gkey(mp));
  402. if (othern != mp) { /* is colliding node out of its main position? */
  403. /* yes; move colliding node into free position */
  404. while (othern + gnext(othern) != mp) /* find previous */
  405. othern += gnext(othern);
  406. gnext(othern) = cast_int(f - othern); /* rechain to point to 'f' */
  407. *f = *mp; /* copy colliding node into free pos. (mp->next also goes) */
  408. if (gnext(mp) != 0) {
  409. gnext(f) += cast_int(mp - f); /* correct 'next' */
  410. gnext(mp) = 0; /* now 'mp' is free */
  411. }
  412. setnilvalue(gval(mp));
  413. }
  414. else { /* colliding node is in its own main position */
  415. /* new node will go into free position */
  416. if (gnext(mp) != 0)
  417. gnext(f) = cast_int((mp + gnext(mp)) - f); /* chain new position */
  418. else lua_assert(gnext(f) == 0);
  419. gnext(mp) = cast_int(f - mp);
  420. mp = f;
  421. }
  422. }
  423. setnodekey(L, &mp->i_key, key);
  424. luaC_barrierback(L, t, key);
  425. lua_assert(ttisnil(gval(mp)));
  426. return gval(mp);
  427. }
  428. /*
  429. ** search function for integers
  430. */
  431. const TValue *luaH_getint (Table *t, lua_Integer key) {
  432. /* (1 <= key && key <= t->sizearray) */
  433. if (l_castS2U(key - 1) < t->sizearray)
  434. return &t->array[key - 1];
  435. else {
  436. Node *n = hashint(t, key);
  437. for (;;) { /* check whether 'key' is somewhere in the chain */
  438. if (ttisinteger(gkey(n)) && ivalue(gkey(n)) == key)
  439. return gval(n); /* that's it */
  440. else {
  441. int nx = gnext(n);
  442. if (nx == 0) break;
  443. n += nx;
  444. }
  445. };
  446. return luaO_nilobject;
  447. }
  448. }
  449. /*
  450. ** search function for short strings
  451. */
  452. const TValue *luaH_getstr (Table *t, TString *key) {
  453. Node *n = hashstr(t, key);
  454. lua_assert(key->tt == LUA_TSHRSTR);
  455. for (;;) { /* check whether 'key' is somewhere in the chain */
  456. const TValue *k = gkey(n);
  457. if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))
  458. return gval(n); /* that's it */
  459. else {
  460. int nx = gnext(n);
  461. if (nx == 0) break;
  462. n += nx;
  463. }
  464. };
  465. return luaO_nilobject;
  466. }
  467. /*
  468. ** main search function
  469. */
  470. const TValue *luaH_get (Table *t, const TValue *key) {
  471. switch (ttype(key)) {
  472. case LUA_TSHRSTR: return luaH_getstr(t, tsvalue(key));
  473. case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
  474. case LUA_TNIL: return luaO_nilobject;
  475. case LUA_TNUMFLT: {
  476. lua_Integer k;
  477. if (numisinteger(fltvalue(key), &k)) /* index is int? */
  478. return luaH_getint(t, k); /* use specialized version */
  479. /* else go through */
  480. }
  481. default: {
  482. Node *n = mainposition(t, key);
  483. for (;;) { /* check whether 'key' is somewhere in the chain */
  484. if (luaV_rawequalobj(gkey(n), key))
  485. return gval(n); /* that's it */
  486. else {
  487. int nx = gnext(n);
  488. if (nx == 0) break;
  489. n += nx;
  490. }
  491. };
  492. return luaO_nilobject;
  493. }
  494. }
  495. }
  496. /*
  497. ** beware: when using this function you probably need to check a GC
  498. ** barrier and invalidate the TM cache.
  499. */
  500. TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
  501. const TValue *p = luaH_get(t, key);
  502. if (p != luaO_nilobject)
  503. return cast(TValue *, p);
  504. else return luaH_newkey(L, t, key);
  505. }
  506. void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {
  507. const TValue *p = luaH_getint(t, key);
  508. TValue *cell;
  509. if (p != luaO_nilobject)
  510. cell = cast(TValue *, p);
  511. else {
  512. TValue k;
  513. setivalue(&k, key);
  514. cell = luaH_newkey(L, t, &k);
  515. }
  516. setobj2t(L, cell, value);
  517. }
  518. static int unbound_search (Table *t, unsigned int j) {
  519. unsigned int i = j; /* i is zero or a present index */
  520. j++;
  521. /* find 'i' and 'j' such that i is present and j is not */
  522. while (!ttisnil(luaH_getint(t, j))) {
  523. i = j;
  524. if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */
  525. /* table was built with bad purposes: resort to linear search */
  526. i = 1;
  527. while (!ttisnil(luaH_getint(t, i))) i++;
  528. return i - 1;
  529. }
  530. j *= 2;
  531. }
  532. /* now do a binary search between them */
  533. while (j - i > 1) {
  534. unsigned int m = (i+j)/2;
  535. if (ttisnil(luaH_getint(t, m))) j = m;
  536. else i = m;
  537. }
  538. return i;
  539. }
  540. /*
  541. ** Try to find a boundary in table 't'. A 'boundary' is an integer index
  542. ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
  543. */
  544. int luaH_getn (Table *t) {
  545. unsigned int j = t->sizearray;
  546. if (j > 0 && ttisnil(&t->array[j - 1])) {
  547. /* there is a boundary in the array part: (binary) search for it */
  548. unsigned int i = 0;
  549. while (j - i > 1) {
  550. unsigned int m = (i+j)/2;
  551. if (ttisnil(&t->array[m - 1])) j = m;
  552. else i = m;
  553. }
  554. return i;
  555. }
  556. /* else must find a boundary in hash part */
  557. else if (isdummy(t->node)) /* hash part is empty? */
  558. return j; /* that is easy... */
  559. else return unbound_search(t, j);
  560. }
  561. #if defined(LUA_DEBUG)
  562. Node *luaH_mainposition (const Table *t, const TValue *key) {
  563. return mainposition(t, key);
  564. }
  565. int luaH_isdummy (Node *n) { return isdummy(n); }
  566. #endif