On Wed, Oct 28, 2009 at 9:35 PM, Alex Osborne <a...@meshy.org> wrote:
> John Harrop wrote: > > Probably the seq .hashCode should consider only the first N elements > > for some maximum N and if two longer (or even infinite) sequences > > collide so be it. > > I strongly disagree. Choosing some arbitrary magic cutoff point just > seems cause for trouble and much confusion. For the specific case of hashCode, no; identical values must have identical hashes but different values need not have different hashes. Collisions due to the hypothetical cutoff get exponentially less likely with each additional increment of 1 of the cutoff length. You're right though that they still won't work in hashmaps and hashsets because the equals test will hang when the sequences are actually equal. This also stops them working in treemaps and treesets (even if we added Comparable to ISeq to use lexicographic order and comparisons of the elements, or supplied a comparator that did so; and even if the seq-compare function gave up after N identical pairs of elements, resulting in hash collisions). A workaround if you want to index something by infinite (or just very large) seqs might be to use (take n the-seq) for some constant n chosen large enough for the truncated sequences to tend not to collide in practice, with some contingency for the case of collisions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---