aboutsummaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-11 15:44:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-11 15:44:28 -0300
commitb6d91e24e23edfe98ad732660fd456e91658edb9 (patch)
treea66fb8348758f32df6c5d5ab1af1aece2a63009f /hash.c
parenta82ab0852eaca43cb56be5134833c97e6bb7ac98 (diff)
downloadlua-b6d91e24e23edfe98ad732660fd456e91658edb9.tar.gz
lua-b6d91e24e23edfe98ad732660fd456e91658edb9.tar.bz2
lua-b6d91e24e23edfe98ad732660fd456e91658edb9.zip
"tag" changed to "ttype" (since now tag has other meaning)
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/hash.c b/hash.c
index 3ed5065d..430eb73b 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.33 1997/02/11 11:35:05 roberto Exp roberto $"; 6char *rcs_hash="$Id: hash.c,v 2.34 1997/02/26 17:38:41 roberto Unstable roberto $";
7 7
8 8
9#include "mem.h" 9#include "mem.h"
@@ -51,7 +51,7 @@ int luaI_redimension (int nhash)
51static int hashindex (Hash *t, Object *ref) /* hash function */ 51static int hashindex (Hash *t, Object *ref) /* hash function */
52{ 52{
53 long int h; 53 long int h;
54 switch (tag(ref)) { 54 switch (ttype(ref)) {
55 case LUA_T_NUMBER: 55 case LUA_T_NUMBER:
56 h = (long int)nvalue(ref); break; 56 h = (long int)nvalue(ref); break;
57 case LUA_T_STRING: case LUA_T_USERDATA: 57 case LUA_T_STRING: case LUA_T_USERDATA:
@@ -72,8 +72,8 @@ static int hashindex (Hash *t, Object *ref) /* hash function */
72 72
73int lua_equalObj (Object *t1, Object *t2) 73int lua_equalObj (Object *t1, Object *t2)
74{ 74{
75 if (tag(t1) != tag(t2)) return 0; 75 if (ttype(t1) != ttype(t2)) return 0;
76 switch (tag(t1)) 76 switch (ttype(t1))
77 { 77 {
78 case LUA_T_NIL: return 1; 78 case LUA_T_NIL: return 1;
79 case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); 79 case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
@@ -90,7 +90,7 @@ int lua_equalObj (Object *t1, Object *t2)
90static int present (Hash *t, Object *ref) 90static int present (Hash *t, Object *ref)
91{ 91{
92 int h = hashindex(t, ref); 92 int h = hashindex(t, ref);
93 while (tag(ref(node(t, h))) != LUA_T_NIL) 93 while (ttype(ref(node(t, h))) != LUA_T_NIL)
94 { 94 {
95 if (lua_equalObj(ref, ref(node(t, h)))) 95 if (lua_equalObj(ref, ref(node(t, h))))
96 return h; 96 return h;
@@ -108,7 +108,7 @@ static Node *hashnodecreate (int nhash)
108 int i; 108 int i;
109 Node *v = newvector (nhash, Node); 109 Node *v = newvector (nhash, Node);
110 for (i=0; i<nhash; i++) 110 for (i=0; i<nhash; i++)
111 tag(ref(&v[i])) = LUA_T_NIL; 111 ttype(ref(&v[i])) = LUA_T_NIL;
112 return v; 112 return v;
113} 113}
114 114
@@ -149,7 +149,7 @@ void lua_hashmark (Hash *h)
149 for (i=0; i<nhash(h); i++) 149 for (i=0; i<nhash(h); i++)
150 { 150 {
151 Node *n = node(h,i); 151 Node *n = node(h,i);
152 if (tag(ref(n)) != LUA_T_NIL) 152 if (ttype(ref(n)) != LUA_T_NIL)
153 { 153 {
154 lua_markobject(&n->ref); 154 lua_markobject(&n->ref);
155 lua_markobject(&n->val); 155 lua_markobject(&n->val);
@@ -163,14 +163,14 @@ static void call_fallbacks (void)
163{ 163{
164 Hash *curr_array; 164 Hash *curr_array;
165 Object t; 165 Object t;
166 tag(&t) = LUA_T_ARRAY; 166 ttype(&t) = LUA_T_ARRAY;
167 for (curr_array = listhead; curr_array; curr_array = curr_array->next) 167 for (curr_array = listhead; curr_array; curr_array = curr_array->next)
168 if (markarray(curr_array) != 1) 168 if (markarray(curr_array) != 1)
169 { 169 {
170 avalue(&t) = curr_array; 170 avalue(&t) = curr_array;
171 luaI_gcFB(&t); 171 luaI_gcFB(&t);
172 } 172 }
173 tag(&t) = LUA_T_NIL; 173 ttype(&t) = LUA_T_NIL;
174 luaI_gcFB(&t); /* end of list */ 174 luaI_gcFB(&t); /* end of list */
175} 175}
176 176
@@ -235,7 +235,7 @@ static void rehash (Hash *t)
235 for (i=0; i<nold; i++) 235 for (i=0; i<nold; i++)
236 { 236 {
237 Node *n = vold+i; 237 Node *n = vold+i;
238 if (tag(ref(n)) != LUA_T_NIL && tag(val(n)) != LUA_T_NIL) 238 if (ttype(ref(n)) != LUA_T_NIL && ttype(val(n)) != LUA_T_NIL)
239 *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */ 239 *node(t, present(t, ref(n))) = *n; /* copy old node to new hahs */
240 } 240 }
241 luaI_free(vold); 241 luaI_free(vold);
@@ -248,7 +248,7 @@ static void rehash (Hash *t)
248Object *lua_hashget (Hash *t, Object *ref) 248Object *lua_hashget (Hash *t, Object *ref)
249{ 249{
250 int h = present(t, ref); 250 int h = present(t, ref);
251 if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h)); 251 if (ttype(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
252 else return NULL; 252 else return NULL;
253} 253}
254 254
@@ -263,7 +263,7 @@ Object *lua_hashdefine (Hash *t, Object *ref)
263 Node *n; 263 Node *n;
264 h = present(t, ref); 264 h = present(t, ref);
265 n = node(t, h); 265 n = node(t, h);
266 if (tag(ref(n)) == LUA_T_NIL) 266 if (ttype(ref(n)) == LUA_T_NIL)
267 { 267 {
268 nuse(t)++; 268 nuse(t)++;
269 if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT) 269 if ((float)nuse(t) > (float)nhash(t)*REHASH_LIMIT)
@@ -273,7 +273,7 @@ Object *lua_hashdefine (Hash *t, Object *ref)
273 n = node(t, h); 273 n = node(t, h);
274 } 274 }
275 *ref(n) = *ref; 275 *ref(n) = *ref;
276 tag(val(n)) = LUA_T_NIL; 276 ttype(val(n)) = LUA_T_NIL;
277 } 277 }
278 return (val(n)); 278 return (val(n));
279} 279}
@@ -289,7 +289,8 @@ static void hashnext (Hash *t, int i)
289{ 289{
290 if (i >= nhash(t)) 290 if (i >= nhash(t))
291 return; 291 return;
292 while (tag(ref(node(t,i))) == LUA_T_NIL || tag(val(node(t,i))) == LUA_T_NIL) 292 while (ttype(ref(node(t,i))) == LUA_T_NIL ||
293 ttype(val(node(t,i))) == LUA_T_NIL)
293 { 294 {
294 if (++i >= nhash(t)) 295 if (++i >= nhash(t))
295 return; 296 return;