MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mainposition

Function mainposition

3rd/lua-5.4.3/src/ltable.c:141–176  ·  view source on GitHub ↗

** returns the 'main' position of an element in a table (that is, ** the index of its hash value). The key comes broken (tag in 'ktt' ** and value in 'vkl') so that we can call it on keys inserted into ** nodes. */

Source from the content-addressed store, hash-verified

139** nodes.
140*/
141static Node *mainposition (const Table *t, int ktt, const Value *kvl) {
142 switch (withvariant(ktt)) {
143 case LUA_VNUMINT: {
144 lua_Integer key = ivalueraw(*kvl);
145 return hashint(t, key);
146 }
147 case LUA_VNUMFLT: {
148 lua_Number n = fltvalueraw(*kvl);
149 return hashmod(t, l_hashfloat(n));
150 }
151 case LUA_VSHRSTR: {
152 TString *ts = tsvalueraw(*kvl);
153 return hashstr(t, ts);
154 }
155 case LUA_VLNGSTR: {
156 TString *ts = tsvalueraw(*kvl);
157 return hashpow2(t, luaS_hashlongstr(ts));
158 }
159 case LUA_VFALSE:
160 return hashboolean(t, 0);
161 case LUA_VTRUE:
162 return hashboolean(t, 1);
163 case LUA_VLIGHTUSERDATA: {
164 void *p = pvalueraw(*kvl);
165 return hashpointer(t, p);
166 }
167 case LUA_VLCF: {
168 lua_CFunction f = fvalueraw(*kvl);
169 return hashpointer(t, f);
170 }
171 default: {
172 GCObject *o = gcvalueraw(*kvl);
173 return hashpointer(t, o);
174 }
175 }
176}
177
178
179/*

Callers 2

mainpositionTVFunction · 0.85
luaH_newkeyFunction · 0.85

Calls 2

l_hashfloatFunction · 0.85
luaS_hashlongstrFunction · 0.85

Tested by

no test coverage detected