<< Back to previous view

[CLJ-1070] PersistentQueue's hash function does not match its equality Created: 15/Sep/12  Updated: 20/Oct/12  Resolved: 20/Oct/12

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.4
Fix Version/s: Release 1.5

Type: Defect Priority: Major
Reporter: Philip Potter Assignee: Philip Potter
Resolution: Completed Votes: 0
Labels: None

Attachments: File 001-fix-PersistentQueue-hash.clj     File 001-make-PersistentQueue-hash-match-equiv.diff     File 002-make-PersistentQueue-hash-match-equiv.diff    
Patch: Code and Test
Approval: Ok


There are two issues:

1) PersistentQueue's hash function doesn't match its equiv function:

(def iq (conj clojure.lang.PersistentQueue/EMPTY (Integer. -1)))
(def lq (conj clojure.lang.PersistentQueue/EMPTY (Long. -1)))
[(= iq lq) (= (hash iq) (hash lq))]
;=> [true false]

2) PersistentQueue's hash function doesn't match PersistentVector's hash:

(def q (conj clojure.lang.PersistentQueue/EMPTY 1 2 3))
[(= [1 2 3] q) (= (hash [1 2 3]) (hash q))]
;=> [true false]

Comment by Philip Potter [ 15/Sep/12 1:52 PM ]

Clojure-dev discussion: https://groups.google.com/d/topic/clojure-dev/ME3-Ke-RbNk/discussion

Comment by Philip Potter [ 15/Sep/12 2:34 PM ]

Attached patch 001-make-PersistentQueue-hash-match-equiv.diff, 15/Sep/12.

Comment by Philip Potter [ 15/Sep/12 4:56 PM ]

Attached 002-make-PersistentQueue-hash-match-equiv.diff, 15/Sep/12. This patch supercedes 001-make-PersistentQueue-hash-match-equiv.diff.

Replaced test code which calls to Util/hasheq with code which calls hash instead.

This patch has a minor conflict with my patch for CLJ-1059, since they both add an interface to PersistentQueue (IHashEq here, List for CLJ-1059).

Comment by Chouser [ 18/Sep/12 1:38 AM ]

Thanks for the patch, Philip, it looks good to me.

It really is a pity the implementations of hashCode and hasheq are duplicated. I wonder how important it is to extend Obj? Regardless, that's the approach PersistentQueue was already taking, so changing that would be outside the scope of this ticket anyway.

I can't apply this patch with "git am", but "patch -p 1" works fine. I'm hoping this is a configuration problem on my end, so I'm marking this screened.

Generated at Fri Sep 22 22:54:57 CDT 2017 using JIRA 4.4#649-r158309.