Of course I can use Dict (ObjectIdDict is a sort of Dict), adding entries
as previously written.
Set is even better, but elements of Set are accessed with hash?
E.g. "hello" in s of your example is executed in constant or linear time?
Thanks
Leonardo
P.S. for my clarification: what is reccomended context of use for
ObjectIdDict?
Il giorno domenica 22 novembre 2015 19:05:58 UTC+1, Tim Holy ha scritto:
>
> Why can't you use Set or Dict?
>
> julia> s = Set{ASCIIString}()
> Set{ASCIIString}()
>
> julia> push!(s, "hello")
> Set(ASCIIString["hello"])
>
> julia> push!(s, "world")
> Set(ASCIIString["hello","world"])
>
> julia> "hello" in s
> true
>
> julia> "nope" in s
> false
>
> --Tim
>
> On Sunday, November 22, 2015 09:58:31 AM Leonardo wrote:
> > Hello,
> > I'm looking for an Hash table in Julia (or Hash Set, how is called in
> other
> > programming languages), to efficiently check existence of an element in
> > set, but I haven't found it.
> > I've found ObjectIdDict as alternative, defined as:
> > ObjectIdDict <: Dict{Any,Any}
> > where key and value are equals, capable to store reference any object
> (if
> > I'm not wrong).
> > It has a simple constructor:
> > d = ObjectIdDict()
> > (no type stored is specified, cause previous definition)
> >
> > But - also inspecting code of dict.jl in Base package - I haven't found
> a
> > simple method to add element in set like:
> > push!(d,obj)
> > but only the form
> > d[obj] = obj
> > works. This is correct way to do this? (potentially key and value can be
> > different ...)
> >
> > Many thanks in advance
> >
> > Leonardo
>
>