Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

673 рядки
19 KiB

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