Jeffrey,
Your interpretation is that the original poster wanted to read or write
dictionary entries that had already been found via previous hashing and
searching without again hashing the key (presumably in order to attain
higher performance). That was also my guess. I am interested in this
issue because Julia currently has a mechanism to refer to a specific object
inside a container: the Ref{T} type. My understanding is that this type
was mainly created in order to build safer Julia/C interfaces, but one
could imagine using it more generally. Unfortunately (last time I checked)
there is a performance problem with Ref{T}: these objects are
heap-allocated and so shouldn't be created in inner loops. In addition, as
far as I know, the implementation has not yet been extended to elements of
Dict{K,V}. The sorted containers in DataStructures.jl have a
token/semitoken type associated with them for the purpose of
high-performance access and iteration, but the approach taken in
DataStructures.jl does not generalize to other Julia containers such as the
standard Dict{K,V}.
The C++ standard containers all have 'iterators' for this purpose. Maybe
some thought could be given to extending the Ref{T} framework to
across-the-board high-performance references to objects inside containers
in some future version of Julia.
-- Steve
On Monday, January 18, 2016 at 1:22:09 PM UTC-5, Jeffrey Sarnoff wrote:
>
> Steve,
> afaik, depending upon the hash implementation, the only advantage might be
> moderately faster lookup but the cost in generality often would outweigh
> that.
>
> On Thursday, January 14, 2016 at 10:44:01 PM UTC-5, [email protected]
> wrote:
>>
>> Could I ask what would be an application of this capability (if it were
>> possible)? -- Steve Vavasis
>>
>> On Wednesday, January 13, 2016 at 3:59:57 PM UTC-5, Ritchie Lee 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!
>>>
>>