MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / findindex

Function findindex

lua/ltable.c:171–193  ·  view source on GitHub ↗

** returns the index of a `key' for table traversals. First goes all ** elements in the array part, then elements in the hash part. The ** beginning of a traversal is signalled by -1. */

Source from the content-addressed store, hash-verified

169** beginning of a traversal is signalled by -1.
170*/
171static int findindex (lua_State *L, Table *t, StkId key) {
172 int i;
173 if (ttisnil(key)) return -1; /* first iteration */
174 i = arrayindex(key);
175 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
176 return i-1; /* yes; that's the index (corrected to C) */
177 else {
178 Node *n = mainposition(t, key);
179 do { /* check whether `key' is somewhere in the chain */
180 /* key may be dead already, but it is ok to use it in `next' */
181 if (luaO_rawequalObj(key2tval(n), key) ||
182 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
183 gcvalue(gkey(n)) == gcvalue(key))) {
184 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
185 /* hash elements are numbered after array ones */
186 return i + t->sizearray;
187 }
188 else n = gnext(n);
189 } while (n);
190 luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
191 return 0; /* to avoid warnings */
192 }
193}
194
195
196int luaH_next (lua_State *L, Table *t, StkId key) {

Callers 1

luaH_nextFunction · 0.85

Calls 4

arrayindexFunction · 0.85
mainpositionFunction · 0.85
luaO_rawequalObjFunction · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected