[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Hash table equality pitfall
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] Hash table equality pitfall |
Date: |
Fri, 2 Mar 2012 00:01:00 +0100 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Mar 01, 2012 at 12:45:57PM -1000, Derrell Piper wrote:
> Um, your 5th line resets 'a to 2, which is why they're not comparing
> equal?. Removing that yields the expected results on 4.7.0.5-st:
Whoops, thanks for pointing that out, Derrel. I overlooked it (that's
what you get while quickly writing up such things on the sly at work!).
The fact is that it sizes the hash table only in terms of the next value
in hash-table-prime-lengths, which means it'll be 307 items big.
However, this does not invalidate my main point. If you insert either
more than 307 items in different order or manage to hash two objects
to the same value you get this problem:
#;1> (use srfi-69)
; loading library srfi-69 ...
#;2> (define x (make-hash-table))
#;3> (hash-table-set! x "a" 1)
#;4> (hash-table-set! x "\x00a" 1)
#;5> (define y (make-hash-table))
#;6> (hash-table-set! y "\x00a" 1)
#;7> (hash-table-set! y "a" 1)
#;8> (equal? x y)
#f
while in 4.5.0,
#;1> (use srfi-69)
; loading library srfi-69 ...
#;2> (define x (make-hash-table))
#;3> (hash-table-set! x "a" 1)
#;4> (hash-table-set! x "\x00a" 1)
#;5> (define y (make-hash-table))
#;6> (hash-table-set! y "a" 1)
#;7> (hash-table-set! y "\x00a" 1)
#;8> (equal? x y)
#t
Cheers,
Peter
--
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
is especially attractive, not only because it can be economically
and scientifically rewarding, but also because it can be an aesthetic
experience much like composing poetry or music."
-- Donald Knuth
- Re: [Chicken-users] Hash table equality pitfall,
Peter Bex <=