From 612f4f57ebb4de7399025acf661837456bc43111 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 6 Jul 2018 06:50:18 -0700 Subject: hash: use full width unsigned type for hash values. Throughout the hashing framework, hashes are reduced into the fixnum range, and returned as cnum. This is not necessary; only the hash-eql and hash-equal functions need to reduce hashes to fixnums. Let's make it ucnum everywhere else, using its full range (no reduction into the [0, NUM_MAX) range). * hash.c (struct hash_ops): hash_fun function pointer returns ucnum instead of cnum. (hash_double): Return unreduced ucnum. Obsolete #ifdef-s removed; the ucnum type gives us a pointer-wide unsigned integer on all platforms. (equal_hash, eql_hash): Return ucnum. Don't reduce values to fixnum range. Some of the way we combine hashes from recursive calls changes; we multiply by at most 2 not to lose too many bits. (eql_hash_op, cobj_eq_hash_op, hash_hash_op): Return ucnum. * hash.h (equal_hash): Declaration updated. * lib.c (cobj_handle_hash_op): Return value changes to ucnum. * lib.h (struct cobj_ops): Hash function pointer's return type changes. (cobj_eq_hash_op, cobj_handle_hash_op): Declarations updated. * struct.c (struct_inst_hash): Return value changes to ucnum. --- struct.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index d1887f19..5e8b1aef 100644 --- a/struct.c +++ b/struct.c @@ -1492,11 +1492,12 @@ static val struct_inst_equal(val left, val right) return t; } -static cnum struct_inst_hash(val obj, int *count, ucnum seed) +static ucnum struct_inst_hash(val obj, int *count, ucnum seed) { struct struct_inst *si = coerce(struct struct_inst *, obj->co.handle); struct struct_type *st = si->type; - cnum nslots = st->nslots, sl, out = equal_hash(st->self, count, seed); + cnum nslots = st->nslots, sl; + ucnum out = equal_hash(st->self, count, seed); check_init_lazy_struct(obj, si); -- cgit v1.2.3