** returns the `main' position of an element in a table (that is, the index ** of its hash value) */
| 95 | ** of its hash value) |
| 96 | */ |
| 97 | static Node *mainposition (const Table *t, const TValue *key) { |
| 98 | switch (ttype(key)) { |
| 99 | case LUA_TNUMBER: |
| 100 | return hashnum(t, nvalue(key)); |
| 101 | case LUA_TLNGSTR: { |
| 102 | TString *s = rawtsvalue(key); |
| 103 | if (s->tsv.extra == 0) { /* no hash? */ |
| 104 | s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash); |
| 105 | s->tsv.extra = 1; /* now it has its hash */ |
| 106 | } |
| 107 | return hashstr(t, rawtsvalue(key)); |
| 108 | } |
| 109 | case LUA_TSHRSTR: |
| 110 | return hashstr(t, rawtsvalue(key)); |
| 111 | case LUA_TBOOLEAN: |
| 112 | return hashboolean(t, bvalue(key)); |
| 113 | case LUA_TLIGHTUSERDATA: |
| 114 | return hashpointer(t, pvalue(key)); |
| 115 | case LUA_TLCF: |
| 116 | return hashpointer(t, fvalue(key)); |
| 117 | default: |
| 118 | return hashpointer(t, gcvalue(key)); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /* |
no test coverage detected