diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-05 16:25:09 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-05 16:25:09 -0300 |
commit | 088cc3f3802b98e613f1348b15679ecd187a435b (patch) | |
tree | 97066ec6d05f7c0e00f8fda90abdabcfb2a9d384 | |
parent | 5034be66359eca9d7aea7edc1c51c71bf42f29c3 (diff) | |
download | lua-088cc3f3802b98e613f1348b15679ecd187a435b.tar.gz lua-088cc3f3802b98e613f1348b15679ecd187a435b.tar.bz2 lua-088cc3f3802b98e613f1348b15679ecd187a435b.zip |
evitar, durante consultas, criacao de nos nao encontrados.
-rw-r--r-- | hash.c | 17 | ||||
-rw-r--r-- | hash.h | 3 |
2 files changed, 18 insertions, 2 deletions
@@ -4,7 +4,7 @@ | |||
4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 | 4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | char *rcs_hash="$Id: hash.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; | 7 | char *rcs_hash="$Id: hash.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; |
8 | 8 | ||
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
@@ -213,6 +213,21 @@ Hash *lua_createarray (int nhash) | |||
213 | 213 | ||
214 | 214 | ||
215 | /* | 215 | /* |
216 | ** If the hash node is present, return its pointer, otherwise return a | ||
217 | ** static nil object | ||
218 | */ | ||
219 | Object *lua_hashget (Hash *t, Object *ref) | ||
220 | { | ||
221 | static Object nil_obj = {T_NIL, {NULL}}; | ||
222 | Node *n; | ||
223 | int h = head (t, ref); | ||
224 | if (h < 0) return NULL; | ||
225 | n = present(t, ref, h); | ||
226 | if (n == NULL) return &nil_obj; | ||
227 | else return &n->val; | ||
228 | } | ||
229 | |||
230 | /* | ||
216 | ** If the hash node is present, return its pointer, otherwise create a new | 231 | ** If the hash node is present, return its pointer, otherwise create a new |
217 | ** node for the given reference and also return its pointer. | 232 | ** node for the given reference and also return its pointer. |
218 | ** On error, return NULL. | 233 | ** On error, return NULL. |
@@ -2,7 +2,7 @@ | |||
2 | ** hash.h | 2 | ** hash.h |
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 | 4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 |
5 | ** $Id: hash.h,v 1.1 1993/12/17 18:41:19 celes Exp celes $ | 5 | ** $Id: hash.h,v 2.1 1994/04/20 22:07:57 celes Exp celes $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef hash_h | 8 | #ifndef hash_h |
@@ -26,6 +26,7 @@ typedef struct Hash | |||
26 | Hash *lua_createarray (int nhash); | 26 | Hash *lua_createarray (int nhash); |
27 | void lua_hashmark (Hash *h); | 27 | void lua_hashmark (Hash *h); |
28 | void lua_hashcollector (void); | 28 | void lua_hashcollector (void); |
29 | Object *lua_hashget (Hash *t, Object *ref); | ||
29 | Object *lua_hashdefine (Hash *t, Object *ref); | 30 | Object *lua_hashdefine (Hash *t, Object *ref); |
30 | void lua_next (void); | 31 | void lua_next (void); |
31 | 32 | ||