JuliaGraphs / JuliaGraphs/GraphIO.jl

Support mmap'ed edge lists

Open
#11 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement hacktoberfest
Dominant language
Julia
Stars
62
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Sometimes you want to build a graph from an edgelist file, but don't have 2X memory lying around. So you should mmap the edgelist and then build the graph. Here is a sample implementation.

using Base.Mmap
using Base.Test
using LightGraphs

function elmmap{T}(io::IO, t::T, ne::Integer)
    el = Base.Mmap.mmap(io, Array{Int,2}, (n,2))
    return el
end


function elgraph(el::Array{Int,2}, maxv)
    g = Graph(maxv)
    for i in 1:size(el,1)
        src, dst = el[i,1], el[i,2]
        if src > nv(g) || dst > nv(g)
            add_vertex!(g, maximum(src,dst) - nv(g))
        end
        add_edge!(g, src, dst)
    end
    return g
end


n = 100
write("tmp.bin", [1:n 2*(1:n)])
fp = elmmap(open("tmp.bin", "r"), Int, n)
@test fp == [1:n 2*(1:n)]
g = elgraph(fp, 2n)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's sample elmmap and elgraph functions, then locate the existing edge-list loading entry points in GraphIO.jl. Verify how a memory-mapped edge list should be exposed and test the shown tmp.bin workflow, including the expected mapped array and graph construction behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.