summaryrefslogtreecommitdiff
path: root/ltable.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltable.c')
-rw-r--r--ltable.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/ltable.c b/ltable.c
index a7d4f36a..9929146d 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.42 2000/05/11 18:57:19 roberto Exp roberto $ 2** $Id: ltable.c,v 1.43 2000/05/24 13:54:49 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -121,6 +121,28 @@ int luaH_pos (lua_State *L, const Hash *t, const TObject *key) {
121 (int)(((const char *)v - (const char *)(&t->node[0].val))/sizeof(Node)); 121 (int)(((const char *)v - (const char *)(&t->node[0].val))/sizeof(Node));
122} 122}
123 123
124/*
125** try to remove a key without value from a table. To avoid problems with
126** hash, change `key' for a number with the same hash.
127*/
128void luaH_remove (Hash *t, TObject *key) {
129 /* do not remove numbers */
130 if (ttype(key) != TAG_NUMBER) {
131 /* try to find a number `n' with the same hash as `key' */
132 Node *mp = luaH_mainposition(t, key);
133 int n = mp - &t->node[0];
134 /* make sure `n' is not in `t' */
135 while (luaH_getnum(t, n) != &luaO_nilobject) {
136 if (t->size >= MAX_INT-n)
137 return; /* give up; (to avoid overflow) */
138 n += t->size;
139 }
140 ttype(key) = TAG_NUMBER;
141 nvalue(key) = n;
142 LUA_ASSERT(L, luaH_mainposition(t, key) == mp, "cannot change hash");
143 }
144}
145
124 146
125static void setnodevector (lua_State *L, Hash *t, lint32 size) { 147static void setnodevector (lua_State *L, Hash *t, lint32 size) {
126 int i; 148 int i;