OK, here is a more serious proposal, comprised of simple, fast operations: To hash a set, you take each of the items in the set, compute the hash value, xor it with the golden number, and square it. Add these results together.
Essentially, it's the sum of the squares of the hashes, the xor is thrown in there primarily so common numbers like 0 have a meaningful effect on the hash (without the xor there's no difference between #{0 1} and #{1}, for example). Here's Clojure code: (declare my-hash) (defn set-hash [coll] (reduce + (for [item (seq coll)] (let [hash-item (.intValue (bit-xor 0x9e3779b9 (my-hash item)))] (unchecked-multiply-int hash-item hash-item))))) (defn my-hash [i] (if (set? i) (set-hash i) (hash i))) Note that the .intValue call can go away if you convert this to Java and use int xor rather than Clojure's xor. This gives really nice spread-out results for similar sets: => (my-hash #{{1 2} 3}) 1067103816 => (my-hash #{{1 3} 2}) 3094912306 => (my-hash #{{1 4} {2 3}}) -3227863472 => (my-hash #{{1 3} {2 4}}) 2855562010 => (my-hash #{[1 1] [2 2]}) 3474272896 => (my-hash #{[1 2] [2 1]}) -1060041718 -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.