commit 088cc3f3802b98e613f1348b15679ecd187a435b
parent 5034be66359eca9d7aea7edc1c51c71bf42f29c3
Author: Waldemar Celes <celes@tecgraf.puc-rio.br>
Date: Fri, 5 Aug 1994 16:24:50 -0300
evitar, durante consultas, criacao de nos nao encontrados.
Diffstat:
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/hash.c b/hash.c
@@ -4,7 +4,7 @@
** Luiz Henrique de Figueiredo - 17 Aug 90
*/
-char *rcs_hash="$Id: hash.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $";
+char *rcs_hash="$Id: hash.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $";
#include <string.h>
#include <stdlib.h>
@@ -213,6 +213,21 @@ Hash *lua_createarray (int nhash)
/*
+** If the hash node is present, return its pointer, otherwise return a
+** static nil object
+*/
+Object *lua_hashget (Hash *t, Object *ref)
+{
+ static Object nil_obj = {T_NIL, {NULL}};
+ Node *n;
+ int h = head (t, ref);
+ if (h < 0) return NULL;
+ n = present(t, ref, h);
+ if (n == NULL) return &nil_obj;
+ else return &n->val;
+}
+
+/*
** If the hash node is present, return its pointer, otherwise create a new
** node for the given reference and also return its pointer.
** On error, return NULL.
diff --git a/hash.h b/hash.h
@@ -2,7 +2,7 @@
** hash.h
** hash manager for lua
** Luiz Henrique de Figueiredo - 17 Aug 90
-** $Id: hash.h,v 1.1 1993/12/17 18:41:19 celes Exp celes $
+** $Id: hash.h,v 2.1 1994/04/20 22:07:57 celes Exp celes $
*/
#ifndef hash_h
@@ -26,6 +26,7 @@ typedef struct Hash
Hash *lua_createarray (int nhash);
void lua_hashmark (Hash *h);
void lua_hashcollector (void);
+Object *lua_hashget (Hash *t, Object *ref);
Object *lua_hashdefine (Hash *t, Object *ref);
void lua_next (void);