I'd suggest you start with the documentation for hash
<http://docs.julialang.org/en/latest/stdlib/base/#Base.hash> and isequal
<http://docs.julialang.org/en/latest/stdlib/base/#Base.isequal>, and look
at some implementation of hash to understand the two argument version.
As far as I understand, hash is basically a integer value that ensures that
if isequal(a,b) == true will cause hash(a) == hash(b). There is nothing to
guard against collisions, so but usually it is cheaper to compare the hash
codes than the `isequal` relation, so you can use the hash comparison as an
indication that the values might be isequal.
hash is not a cryptographic hash function, so it is much faster and has a
shorter bit length. A lot of effort has also been put into making hash(4)
== hash(4.), so that numeric keys becomes more reliable.
Ivar
kl. 20:55:36 UTC+1 fredag 14. november 2014 skrev Simon Danisch følgende:
>
> Hi,
> I hardly have any experience with hashing, so I thought I better ask here,
> before I do something silly.
>
> First, how do you make sets use a custom hashing functions for your own
> types?
> This doesn't seem to work:
>
> *immutable Test*
> *x::ASCIIString*
> *end*
> *Base.hash(h::Test) = hash(h.x)*
> *Set([Test("a"), Test("a")])*
> *=> Set(Any[Test("1"),Test("1")]) # object_id is used*
>
> Secondly, how reliable is the hash, when I use pretty big keys?
>
> *a = Dict{ASCIIString, Any}()*
> *for i=1:10000*
> * a[randstring(10)] = rand(10,10)*
> *end*
> *b = Dict{ASCIIString, Any}()*
> *for i=1:10000*
> * a[randstring(10)] = rand(10,10)*
> *end*
> *d = Dict(*
> *a => 23,*
> *copy(a) => 555,*
> *b => 999,*
> *)*
> *d[copy(a)] => 555*
> *d[copy(b)] => 999*
>
> It works (to my surprise) very well! Do I have to be careful here? How
> likely are collisions?
> To give my problem a little bit more plasticity, here is what I want to do:
> I have templated shader and create the different versions of the shader
> via mustache and views (the views are dicts in my case).
> Then I want to make the shader accessible via the view, so that I don't
> have to compile shaders that I already have compiled.
> Or would it be better to just use the whole source code of the shader as a
> key?
>
> Thanks a lot,
> Simon
>
>