diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-17 12:03:11 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-17 12:03:11 -0300 |
commit | 592a949272de2b71abae3856553ac916fc1880bd (patch) | |
tree | 903b57e796be6180306e559d7fd48745691064c3 /hash.c | |
parent | c4b8b1b9893f253d74db96e74f0e711e5c7350c0 (diff) | |
download | lua-592a949272de2b71abae3856553ac916fc1880bd.tar.gz lua-592a949272de2b71abae3856553ac916fc1880bd.tar.bz2 lua-592a949272de2b71abae3856553ac916fc1880bd.zip |
heranca e nova implementacao do hash.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.3 1994/08/05 19:25:09 celes Exp celes $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.4 1994/08/09 11:24:45 celes Exp celes $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -95,7 +95,6 @@ static int present (Hash *t, Object *ref) | |||
95 | if (h < 0) return h; | 95 | if (h < 0) return h; |
96 | while (tag(ref(node(t, h))) != T_NIL) | 96 | while (tag(ref(node(t, h))) != T_NIL) |
97 | { | 97 | { |
98 | NCOLISSIONS++; | ||
99 | if (tag(ref) == T_NUMBER && tag(ref(node(t, h))) == T_NUMBER && | 98 | if (tag(ref) == T_NUMBER && tag(ref(node(t, h))) == T_NUMBER && |
100 | nvalue(ref) == nvalue(ref(node(t, h))) | 99 | nvalue(ref) == nvalue(ref(node(t, h))) |
101 | ) return h; | 100 | ) return h; |
@@ -260,16 +259,30 @@ static void rehash (Hash *t) | |||
260 | } | 259 | } |
261 | 260 | ||
262 | /* | 261 | /* |
263 | ** If the hash node is present, return its pointer, otherwise return a | 262 | ** If the hash node is present, return its pointer, otherwise search |
264 | ** static nil object | 263 | ** the node at parent table, recursively, if there is parent. |
264 | ** If no parent and the node is not present, return a static nil object. | ||
265 | */ | 265 | */ |
266 | Object *lua_hashget (Hash *t, Object *ref) | 266 | Object *lua_hashget (Hash *t, Object *ref) |
267 | { | 267 | { |
268 | static Object nil_obj = {T_NIL, {NULL}}; | 268 | static Object nil_obj = {T_NIL, {NULL}}; |
269 | int h = present(t, ref); | 269 | Object parent; |
270 | if (h < 0) return NULL; | 270 | int count = 1000; |
271 | if (tag(ref(node(t, h))) == T_NIL) return &nil_obj; | 271 | tag(&parent) = T_STRING; |
272 | else return val(node(t, h)); | 272 | svalue(&parent) = "parent"; |
273 | do | ||
274 | { | ||
275 | int h = present(t, ref); | ||
276 | if (h < 0) return NULL; | ||
277 | if (tag(ref(node(t, h))) != T_NIL) return val(node(t, h)); | ||
278 | |||
279 | h = present(t, &parent); /* assert(p >= 0); */ | ||
280 | t = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ? | ||
281 | avalue(val(node(t, h))) : NULL; | ||
282 | } while (t != NULL && --count); | ||
283 | if (count == 0) | ||
284 | lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)"); | ||
285 | return &nil_obj; | ||
273 | } | 286 | } |
274 | 287 | ||
275 | /* | 288 | /* |
@@ -351,4 +364,3 @@ void lua_next (void) | |||
351 | lua_error ("error in function 'next': reference not found"); | 364 | lua_error ("error in function 'next': reference not found"); |
352 | } | 365 | } |
353 | } | 366 | } |
354 | |||