Ahhh, I finally understand a little bit more about dicts and types.
I'm nearly always using immutable types, which when isbits(type) is true, 
gets optimized in a way, that if they have the same value, they get stored 
as the same object with the same object_id.
This is why I believed for a long time, that user defined types are 
actually hashed by their value.

immutable Vec3i ... end; type Vec3 ... end; immutable T ... end
Set(Vec3i(1,1,1), Vec3i(1,1,1)) => Set(Vec3i(1,1,1));                  with 
isbits(Vec3i) == true
Set(Vec3(1,1,1), Vec3(1,1,1)) => Set(Vec3(1,1,1), Vec3(1,1,1)); with 
isbits(Vec3) == false
Set( T("A"), T("A")) => Set(T("A"), T("A"));                               
 with isbits(T) == false

Which is not that intuitive, if you're not familiar with the type system 
and the compiler...
I hope this helps some other people :)



Am Freitag, 14. November 2014 20:55:36 UTC+1 schrieb Simon Danisch:
>
> 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