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 /hash.c | |
parent | 5034be66359eca9d7aea7edc1c51c71bf42f29c3 (diff) | |
download | lua-088cc3f3802b98e613f1348b15679ecd187a435b.tar.gz lua-088cc3f3802b98e613f1348b15679ecd187a435b.tar.bz2 lua-088cc3f3802b98e613f1348b15679ecd187a435b.zip |
evitar, durante consultas, criacao de nos nao encontrados.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 17 |
1 files changed, 16 insertions, 1 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. |