/* ** If the hash node is present, return its pointer, otherwise create a luaM_new ** node for the given reference and also return its pointer. */ TObject *luaH_set(Hash *t, TObject *r) { Node *n = node(t, present(t, r)); if (ttype(ref(n)) == LUA_T_NIL) { nuse(t)++; if ((float)nuse(t) > (float)nhash(t) * REHASH_LIMIT) { rehash(t); n = node(t, present(t, r)); } *ref(n) = *r; ttype(val(n)) = LUA_T_NIL; } return (val(n)); }
/* ** Create a new hash. Return the hash pointer or NULL on error. */ static Hash *hashcreate (int nhash) { Hash *t = new(Hash); nhash = luaI_redimension((int)((float)nhash/REHASH_LIMIT)); nodevector(t) = hashnodecreate(nhash); nhash(t) = nhash; nuse(t) = 0; markarray(t) = 0; return t; }
/* ** If the hash node is present, return its pointer, otherwise create a new ** node for the given reference and also return its pointer. */ Object *lua_hashdefine (Hash *t, Object *ref) { int h; Node *n; h = present(t, ref); n = node(t, h); if (tag(ref(n)) == LUA_T_NIL) { nuse(t)++; if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT) { rehash(t); h = present(t, ref); n = node(t, h); } *ref(n) = *ref; tag(val(n)) = LUA_T_NIL; } return (val(n)); }
Hash *luaH_new(int32 nhash) { Hash *t = luaM_new(Hash); nhash = luaO_redimension((int32)((float)nhash / REHASH_LIMIT)); nodevector(t) = hashnodecreate(nhash); nhash(t) = nhash; nuse(t) = 0; t->htag = TagDefault; luaO_insertlist(&roottable, (GCnode *)t); nblocks += gcsize(nhash); return t; }