let u = "☝️", v = "✌️"
let vertices = Set(arrayLiteral: u, v)
let e = Edge(source: u, destination: v)
let edges = Set(arrayLiteral: e)
let graph = Graph(vertices: vertices, edges: edges)
Weighted directed graph:
let w_e = WeightedEdge(source: u, destination: v, weight: 3.9)
let weightedEdges = Set(arrayLiteral: w_e)
let weightedGraph = Graph(vertices: vertices, edges: weightedEdges)
DFS from source:
let simpleGraphAnnotation = dfs(graph, source: v)
DFS on graph:
let simpleGraphAnnotation = dfs(graph)
BFS from source:
let simpleGraphAnnotation = bfs(graph, source: v)
Finding paths from graph annotations:
let parentByVertex = simpleGraphAnnotation.parentByVertex
let result = findPath(parentByVertex: parentByVertex, source: s, destination: d)
CocoaPods installation
ImmutableGraph is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ImmutableGraph"
Swift Package installation
If your package depends on ImmutableGraph, add the following dependency to your Package.swift:
ImmutableGraph
Examples
Directed graph:
Weighted directed graph:
DFS from source:
DFS on graph:
BFS from source:
Finding paths from graph annotations:
CocoaPods installation
ImmutableGraph
is available through CocoaPods. To install it, simply add the following line to yourPodfile
:Swift Package installation
If your package depends on
ImmutableGraph
, add the following dependency to yourPackage.swift
:Generate Xcode project
Testing
macOS
Docker Linux
IMPORTANT: regenerate Linux test list executing
Execute on base
swift:5.2
imageor create a new image based on
Dockerfile
and run itNotes
This library was built using TDD.
Some of the graphs used to unit test BFS and DFS algorithms come from Algorithms with Attitude YouTube channel’s related videos:
Author
Nicola Di Pol, horothesun@gmail.com
License
ImmutableGraph
is available under the MIT license. See the LICENSE file for more info.