aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-28 13:10:51 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-28 13:10:51 -0200
commit2b301d711b1fedf2fc31beba67e2c096b6d933a0 (patch)
treed7a8a38591c08dff2d5cb8f4297e896b29b5bb39
parent10bdd838440b082aaf70748571b443f7c941db81 (diff)
downloadlua-2b301d711b1fedf2fc31beba67e2c096b6d933a0.tar.gz
lua-2b301d711b1fedf2fc31beba67e2c096b6d933a0.tar.bz2
lua-2b301d711b1fedf2fc31beba67e2c096b6d933a0.zip
new hash function; hash value for strings are kept with the string
-rw-r--r--hash.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/hash.c b/hash.c
index 82282b1a..89b28fa6 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.18 1994/11/17 13:58:57 roberto Exp roberto $"; 6char *rcs_hash="$Id: hash.c,v 2.20 1994/11/25 19:27:03 roberto Exp $";
7 7
8#include "mem.h" 8#include "mem.h"
9#include "opcode.h" 9#include "opcode.h"
@@ -56,15 +56,15 @@ static int hashindex (Hash *t, Object *ref) /* hash function */
56 return (((int)nvalue(ref))%nhash(t)); 56 return (((int)nvalue(ref))%nhash(t));
57 case LUA_T_STRING: 57 case LUA_T_STRING:
58 { 58 {
59 int h; 59 unsigned long h = tsvalue(ref)->hash;
60 char *name = svalue(ref); 60 if (h == 0)
61 for (h=0; *name!=0; name++) /* interpret name as binary number */ 61 {
62 { 62 char *name = svalue(ref);
63 h <<= 8; 63 while (*name)
64 h += (unsigned char) *name; /* avoid sign extension */ 64 h = ((h<<5)-h)^(unsigned char)*(name++);
65 h %= nhash(t); /* make it a valid index */ 65 tsvalue(ref)->hash = h;
66 } 66 }
67 return h; 67 return h%nhash(t); /* make it a valid index */
68 } 68 }
69 case LUA_T_FUNCTION: 69 case LUA_T_FUNCTION:
70 return (((int)bvalue(ref))%nhash(t)); 70 return (((int)bvalue(ref))%nhash(t));