EdgeIteration

Graft provides the EdgeIter type for fast, alloc-free edge iteration. This type simplifies the indexing and construction of sparse matrices.

The following example demonstrates the usage of EdgeIter:

julia> using Graft

julia> g = completegraph(3)
Graph(3 vertices, 6 edges, Symbol[] vertex properties, Symbol[] edge properties)

julia> # Build an iterator for all edges in the graph
       eit = edges(g)
6-element Graft.EdgeIter:
 1=>2
 1=>3
 2=>1
 2=>3
 3=>1
 3=>2

julia> # Iterate through edges
       for e in eit
          # Do something here
       end

julia> # Use in list comprehensions
       [e for e in eit]
6-element Array{Pair{Int64,Int64},1}:
 1=>2
 1=>3
 2=>1
 2=>3
 3=>1
 3=>2

julia> # Get the third edge in the graph
       eit[3]
2=>1

julia> # Get a subset of the edges in the graph (returns a new iterator)
       eit[1:3]
3-element Graft.EdgeIter:
 1=>2
 1=>3
 2=>1

julia> # Concatenate two iterators
       vcat(eit[4:6], eit[1:3])
6-element Graft.EdgeIter:
 2=>3
 3=>1
 3=>2
 1=>2
 1=>3
 2=>1

julia> # Edge iterator implements the AbstractVector{Pair{Int,Int}} interface
       sort(ans)
6-element Array{Pair{Int64,Int64},1}:
 1=>2
 1=>3
 2=>1
 2=>3
 3=>1
 3=>2

Detailed documentation:

# Graft.EdgeIterType.

An abstraction for alloc-free, fast edge iteration

source

# Base.getindexMethod.

Get the ith edge in the iterator

source

# Base.getindexMethod.

Get a new iterator containing a subset of the edges

source

# Base.getindexMethod.

Get a copy of the iterator

source

# Base.vcatMethod.

Concatenate two iterators

source