How to use relation "many-to-many" with hashing ? like Dict

I need fast searching for relation many-to-many
julia> a=[1 1 1 2 2 3]’
6×1 Array{Int64,2}:
1
1
1
2
2
3

julia> b=[100 100 200 300 300 500]’
6×1 Array{Int64,2}:
100
100
200
300
300
500

julia> Dict(zip(a,b))
Dict{Int64,Int64} with 3 entries:
2 => 300
3 => 500
1 => 200

julia> Special_Dict=hcat(a,b)
6×2 Array{Int64,2}:
1 100
1 100
1 200
2 300
2 300
3 500
I am looking for somthig fast
Special_Dict(1) >100 100 200
Special_Dict(2) >300 300

Special_Dict[:,1].==1 is to slow
Paul

It is not clear what the question is.

And please always quote blocks of code using triple backticks (or highlight the code and click the </> button in Discourse).

3 Likes

Is this what you wanted?

a=[1 1 1 2 2 3]'
b=[100 100 200 300 300 500]'
Special_Dict = Dict{Int, Vector{Int}}()
foreach((k,v) -> push!(get!(Special_Dict, k, Int[]), v), a, b)

See also Disjoint-set data structure - Wikipedia …I think there is one in GitHub - JuliaCollections/DataStructures.jl: Julia implementation of Data structures

Yes is it ,tahans very much
Paul
W dniu 2017-03-04 o 10:22, Bogumił Kamiński pisze: