|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
-** $Id: ltable.c,v 1.42 2000/05/11 18:57:19 roberto Exp roberto $
|
|
|
+** $Id: ltable.c,v 1.43 2000/05/24 13:54:49 roberto Exp roberto $
|
|
|
** Lua tables (hash)
|
|
|
** See Copyright Notice in lua.h
|
|
|
*/
|
|
@@ -121,6 +121,28 @@ int luaH_pos (lua_State *L, const Hash *t, const TObject *key) {
|
|
|
(int)(((const char *)v - (const char *)(&t->node[0].val))/sizeof(Node));
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+** try to remove a key without value from a table. To avoid problems with
|
|
|
+** hash, change `key' for a number with the same hash.
|
|
|
+*/
|
|
|
+void luaH_remove (Hash *t, TObject *key) {
|
|
|
+ /* do not remove numbers */
|
|
|
+ if (ttype(key) != TAG_NUMBER) {
|
|
|
+ /* try to find a number `n' with the same hash as `key' */
|
|
|
+ Node *mp = luaH_mainposition(t, key);
|
|
|
+ int n = mp - &t->node[0];
|
|
|
+ /* make sure `n' is not in `t' */
|
|
|
+ while (luaH_getnum(t, n) != &luaO_nilobject) {
|
|
|
+ if (t->size >= MAX_INT-n)
|
|
|
+ return; /* give up; (to avoid overflow) */
|
|
|
+ n += t->size;
|
|
|
+ }
|
|
|
+ ttype(key) = TAG_NUMBER;
|
|
|
+ nvalue(key) = n;
|
|
|
+ LUA_ASSERT(L, luaH_mainposition(t, key) == mp, "cannot change hash");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
static void setnodevector (lua_State *L, Hash *t, lint32 size) {
|
|
|
int i;
|