chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Hash all the record slots


From: lemonboy
Subject: [Chicken-hackers] [PATCH] Hash all the record slots
Date: Sun, 29 May 2016 22:27:25 +0200

Hello,
While investigating the ticket #1293 [1] I noticed that the hashing
procedures would stop hashing all the vectors
at the 4th element and while that's a valuable way to speed up the
hashing process it causes some problems in
the wild.

If you use a record with N > 4 slots as a key and then set! one of the
last slots after the 4th one the equal?-hash
procedure would return the same hash where equal? definitely fails.

The attached patch fixes this problem by lifting the limit when
hashing tagged vectors aka records, the rationale
behind this decision is that the number of slots a record has is
usually very small and it's more likely to use a
record as a key instead of a huge vector.

While inspecting this I also came across another issue, eq?-hash
crunches some plain values by just xor-ing them
with a random seed, while it calls hash-equal? for complex objects
like records/vectors, that's IMO quite a convoluted
way to implement it (and it might also be wrong as eq? performs a
shallow comparison only) that could be replaced by
stirring [2] the raw C_Word value as that's faster (and incidentally
also what guile does [3]).
(Rinse and repeat for the eqv? version)

Cheers,
LemonBoy

[3] 
http://git.savannah.gnu.org/gitweb/?p=guile.git;a=blob;f=libguile/hash.c;h=d6ddb6b3b631f8f694171fe18eaa7dcb5325df1f;hb=HEAD
[2] https://gist.github.com/badboy/6267743
[1] http://bugs.call-cc.org/ticket/1293



reply via email to

[Prev in Thread] Current Thread [Next in Thread]