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

**URL:** <https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431>\
**Category:** General Usage\
**Created:** [March 4, 2017, 4:29am UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431 "2017-03-04T04:29:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [March 4, 2017, 4:29am UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431/1 "2017-03-04T04:29:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [March 4, 2017, 6:11am UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431/2 "2017-03-04T06:11:48Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 4, 2017, 9:18am UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431/3 "2017-03-04T09:18:35Z")

</div>

Is this what you wanted?

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 4, 2017, 1:02pm UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431/4 "2017-03-04T13:02:42Z")

</div>

See also [Disjoint-set data structure - Wikipedia](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) …I think there is one in [GitHub - JuliaCollections/DataStructures.jl: Julia implementation of Data structures](https://github.com/JuliaCollections/DataStructures.jl)

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [March 6, 2017, 8:34am UTC](https://discourse.julialang.org/t/how-to-use-relation-many-to-many-with-hashing-like-dict/2431/5 "2017-03-06T08:34:10Z")

</div>

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