if i compute CID of 'pr-str' of a clojure map, is it unique?
i want to know if a clojure map may have non-unique hashes when fed to a digest function.
It depends on the digest, not on the map, the fact that it comes from Clojure, or the fact that you've used pr-str
.
By definition, any reasonable digest is a lossy function, so it always allows for conflicts, even if probability for some digests is minuscule.
i have written :one first in my code.
but does it always come before :two?
The order of a hash set/map is undefined. But it is the same for the same object.
However, it can be different for different objects even if the content is the same:
user=> (mapv hash [0 0.])
[0 0]
user=> (pr-str (hash-map 0 0 0. 0))
"{0 0, 0.0 0}"
user=> (pr-str (hash-map 0. 0 0 0))
"{0.0 0, 0 0}"
if i run the above code, will it always return a single unique value?
As per the above, it's not guaranteed. It can never be guaranteed for a lossy function such as a digest.
i imagine clojure maps are sets equipped with a special bind
or >>=
operator that makes 'invoking' the set with one of its elements return whatever was bound to that element.
That doesn't seem to be related to the rest of the question. But no, there's nothing special about sets or maps in Clojure in this regard, and Clojure doesn't have operators.
Sets and maps in Clojure are, among some other things, callable - as simple as that.