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

Reply via email to