# Accessing edges in non-sorted fashion Graphs.jl?

**URL:** <https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261>\
**Category:** Graphs\
**Tags:** lightgraphs, graphs\
**Created:** [October 23, 2021, 11:55am UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261 "2021-10-23T11:55:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [October 23, 2021, 11:55am UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261/1 "2021-10-23T11:55:40Z")

</div>

```julia
g = DiGraph(3);
add_edge!(g, 2, 1)
add_edge!(g, 1, 2)
add_edge!(g, 3, 2)

julia> collect(edges(g))
3-element Vector{LightGraphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 2
 Edge 2 => 1
 Edge 3 => 2

```

edges collected here are obtained in sorted fashion. But How do we obtain the edges in the order we pushed or added ?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 23, 2021, 1:08pm UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261/2 "2021-10-23T13:08:38Z")

</div>

You need to keep track of that yourself. The internal representation of a `SimpleDiGraph` is, well, too simple to represent such information.

---

<div class="post-metadata">

**Author:** ![blociss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blociss/32/16421_2.png) [@blociss](https://discourse.julialang.org/u/blociss)\
**Post date:** [July 25, 2022, 8:56am UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261/3 "2022-07-25T08:56:38Z")

</div>

Did you find a solution with that ?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [August 22, 2022, 6:23pm UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261/4 "2022-08-22T18:23:43Z")

</div>

Sorry I missed that topic. I had the same question once, and the only workaround I found was to implement a custom graph type that stores edges in arrival order. If this is still relevant I can help you do that

---

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [August 25, 2022, 9:12am UTC](https://discourse.julialang.org/t/accessing-edges-in-non-sorted-fashion-graphs-jl/70261/5 "2022-08-25T09:12:40Z")

</div>

I did find solution for this. But dont remember at the moment. I will try to recollect in my old codes over next weekend
