Browse Source

evitar, durante consultas, criacao de nos nao encontrados.

Waldemar Celes 31 years ago
parent
commit
088cc3f380
2 changed files with 18 additions and 2 deletions
  1. 16 1
      hash.c
  2. 2 1
      hash.h

+ 16 - 1
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>
@@ -212,6 +212,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.

+ 2 - 1
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);