Skip to content

Commit

Permalink
Merge pull request #50 from ferranpujolcamins/codable-from-graph
Browse files Browse the repository at this point in the history
Let codable graphs to be initialized from their non-codable versions.
  • Loading branch information
davecom committed Oct 21, 2018
2 parents 9551aae + 0905435 commit d01175e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/SwiftGraph/UnweightedGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public final class CodableUnweightedGraph<V: Codable & Equatable> : UnweightedGr
override public init(vertices: [V]) {
super.init(vertices: vertices)
}

public convenience init(fromGraph g: UnweightedGraph<V>) {
self.init()
vertices = g.vertices
edges = g.edges
}

public required init(from decoder: Decoder) throws {
super.init()
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftGraph/WeightedGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public final class CodableWeightedGraph<V: Codable & Equatable, W: Comparable &
override public init(vertices: [V]) {
super.init(vertices: vertices)
}

public convenience init(fromGraph g: WeightedGraph<V, W>) {
self.init()
vertices = g.vertices
edges = g.edges
}

public required init(from decoder: Decoder) throws {
super.init()
Expand Down

0 comments on commit d01175e

Please sign in to comment.