From 595e55ff7fd02106e7e04bd0db3c2737643fedbd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 16 Dec 2011 17:54:16 -0800 Subject: 2011-12-16 Kaz Kylheku * hash.c (equal_hash): Eliminating displacement from character hashes. Simplifying some code. (eql_hash): Handle fixnums, characters and literals specially, rather than hashing all value types the same way. The shift applicable for object pointers causes adjacent integers to clash. --- ChangeLog | 8 ++++++++ hash.c | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bb2214c..3885dd09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-12-16 Kaz Kylheku + + * hash.c (equal_hash): Eliminating displacement from character + hashes. Simplifying some code. + (eql_hash): Handle fixnums, characters and literals specially, + rather than hashing all value types the same way. The shift + applicable for object pointers causes adjacent integers to clash. + 2011-12-16 Kaz Kylheku * eval.c (expand_vars): Bugfix: use expand_forms rather than diff --git a/hash.c b/hash.c index db7be842..ebec6968 100644 --- a/hash.c +++ b/hash.c @@ -100,17 +100,17 @@ static cnum equal_hash(val obj) case STR: return hash_c_str(obj->st.str); case CHR: - return c_chr(obj) + NUM_MAX / 2; + return c_chr(obj); case NUM: - return c_num(obj) & NUM_MAX; + return c_num(obj); case SYM: case PKG: case ENV: switch (sizeof (mem_t *)) { case 4: - return (((cnum) obj) & NUM_MAX) >> 4; + return ((cnum) obj) >> 4; case 8: default: - return (((cnum) obj) & NUM_MAX) >> 5; + return ((cnum) obj) >> 5; } break; case FUN: @@ -142,14 +142,32 @@ static cnum equal_hash(val obj) static cnum eql_hash(val obj) { - if (bignump(obj)) - return mp_hash(mp(obj)); - switch (sizeof (mem_t *)) { - case 4: - return (((cnum) obj) & NUM_MAX) >> 4; - case 8: default: - return (((cnum) obj) & NUM_MAX) >> 5; + switch (tag(obj)) { + case TAG_PTR: + if (!obj) + return NUM_MAX; + if (obj->t.type == BGNUM) + return mp_hash(mp(obj)); + switch (sizeof (mem_t *)) { + case 4: + return ((cnum) obj) >> 4; + case 8: default: + return ((cnum) obj) >> 5; + } + case TAG_CHR: + return c_chr(obj); + case TAG_NUM: + return c_num(obj); + case TAG_LIT: + switch (sizeof (mem_t *)) { + case 4: + return ((cnum) obj) >> 2; + case 8: default: + return ((cnum) obj) >> 3; + } } + /* notreached */ + abort(); } cnum cobj_hash_op(val obj) -- cgit v1.2.3