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