No, this is not possible. Dicts use the function Base.hashindex to convert a hash into an index into the internal storage arrays (one for keys, one for values, one a bool stating whether used or not, see [1]). However, collisions are likely. For instance, 1 and 18 map to the same index for a length 16 internal storage array:
julia> Base.hashindex(1,16) 16 julia> Base.hashindex(18,16) 16 Thus you need to check for equality too: if the content of the key-array at that location is not equal to the key, the next location is checked until the key is found (or an empty slot is encountered and an error is thrown). [1] https://github.com/JuliaLang/julia/blob/5cbb72ca46791c6491a098399642c00daf97cec0/base/dict.jl#L390 On Wed, 2016-01-13 at 21:59, Ritchie Lee <ritchie....@gmail.com> wrote: > As I understand it, Julia dicts use Base.hash when storing custom types as > keys. Is there a way to look up based on the hash alone? > > e.g., > > type MyType > a::Int > end > > Base.hash(x::MyType) = hash(x.a, hash(MyType)) > > x = MyType(1) > D = Dict{MyType, Bool}() > D[x] = true > > Now, is there a way to lookup using h only? > > h = hash(x) > D[h] > > Is this be safe to do? > > Thanks!