ClojureScript

Order-independent hashing of maps

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

This patch introduces a new function – {cljs.core/hash-imap} – which calculates a hash for a map using the algorithm of {clojure.lang.APersistentMap} and wires it into the {-hash} implementations of the various map types. The benefit is that it is order-independent and thus guarantees a stable hash value congruent with {=} without the need for keyset sorting.

This should also be used in sets once {PersistentTreeSet} lands (along with the tree map).

Activity

Hide
Michał Marczyk added a comment -

Note this calculates the hash modulo 4503599627370496 so it can be represented exactly. Perhaps it would be better to stay within int bounds though?

Show
Michał Marczyk added a comment - Note this calculates the hash modulo 4503599627370496 so it can be represented exactly. Perhaps it would be better to stay within int bounds though?

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: