Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
name = "StaticGraphs"
uuid = "4c8beaf5-199b-59a0-a7f2-21d17de635b6"
version = "0.3.1"
version = "0.4.0"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[weakdeps]
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"

[extensions]
StaticGraphsJLD2Ext = "JLD2"

[compat]
Graphs = "1.4"
JLD2 = "0.1 - 0.6"
julia = "1"
julia = "1.10"

[extras]
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["JLD2", "Test"]
32 changes: 32 additions & 0 deletions ext/StaticGraphsJLD2Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module StaticGraphsJLD2Ext

using JLD2
using StaticGraphs

function StaticGraphs.savesg(fn::AbstractString, g::StaticGraph)
f_ind = g.f_ind
f_vec = g.f_vec
@save fn f_vec f_ind
return 1
end

function StaticGraphs.savesg(fn::AbstractString, g::StaticDiGraph)
f_ind = g.f_ind
f_vec = g.f_vec
b_ind = g.b_ind
b_vec = g.b_vec
@save fn f_vec f_ind b_vec b_ind
return 1
end

function StaticGraphs.loadsg(fn::AbstractString, ::SGFormat)
@load fn f_vec f_ind
return StaticGraph(f_vec, f_ind)
end

function StaticGraphs.loadsg(fn::AbstractString, ::SDGFormat)
@load fn f_vec f_ind b_vec b_ind
return StaticDiGraph(f_vec, f_ind, b_vec, b_ind)
end

end
16 changes: 15 additions & 1 deletion src/StaticGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module StaticGraphs

using Graphs
using JLD2
using SparseArrays

import Base:
Expand Down Expand Up @@ -115,4 +114,19 @@ eltype(::Type{StaticEdgeIter{StaticDiGraph{T, U}}}) where T where U = StaticDiGr

include("overrides.jl")

function __init__()
# Register error hint for the `loadsg` and `savesg` functions
if isdefined(Base.Experimental, :register_error_hint)
Base.Experimental.register_error_hint(MethodError) do io, exc, _, _
if exc.f === loadsg
print(io, "\n\nIn order to load static graphs from binary files, you need \
to load the JLD2.jl package.")
elseif exc.f === savesg
print(io,"\n\nIn order to save static graphs to binary files, you need to \
load the JLD2.jl package.")
end
end
end
end

end # module
29 changes: 3 additions & 26 deletions src/persistence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,8 @@ abstract type StaticGraphFormat <: AbstractGraphFormat end
struct SGFormat <: StaticGraphFormat end
struct SDGFormat <: StaticGraphFormat end

function savesg(fn::AbstractString, g::StaticGraph)
f_ind = g.f_ind
f_vec = g.f_vec
@save fn f_vec f_ind
return 1
end

function savesg(fn::AbstractString, g::StaticDiGraph)
f_ind = g.f_ind
f_vec = g.f_vec
b_ind = g.b_ind
b_vec = g.b_vec
@save fn f_vec f_ind b_vec b_ind
return 1
end

function loadsg(fn::AbstractString, ::SGFormat)
@load fn f_vec f_ind
return StaticGraph(f_vec, f_ind)
end

function loadsg(fn::AbstractString, ::SDGFormat)
@load fn f_vec f_ind b_vec b_ind
return StaticDiGraph(f_vec, f_ind, b_vec, b_ind)
end
function loadsg end
function savesg end

loadgraph(fn::AbstractString, gname::String, s::StaticGraphFormat) = loadsg(fn, s)
savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g)
savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using StaticGraphs
using Graphs
using Graphs.SimpleGraphs
using JLD2
using Test

const testdir = dirname(@__FILE__)
Expand Down
Loading