Swiftpack.co - Package - horothesun/ImmutableGraph


CI Linux CI macOS

SwiftPM Version Platform



Directed graph:

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:

dependencies: [
    .package(url: "https://github.com/horothesun/ImmutableGraph", .upToNextMinor(from: "0.1.0"))

Generate Xcode project

swift package generate-xcodeproj



swift test

Docker Linux

IMPORTANT: regenerate Linux test list executing

swift test --generate-linuxmain

Execute on base swift:5.2 image

docker run --rm \
    --volume "$(pwd):/package" \
    --workdir "/package" \
    swift:5.2 \
    /bin/bash -c "swift test --build-path ./.build/linux"

or create a new image based on Dockerfile and run it

docker build --tag immutable-graph .
docker run --rm immutable-graph


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:


Nicola Di Pol, horothesun@gmail.com


ImmutableGraph is available under the MIT license. See the LICENSE file for more info.


Stars: 5


Used By

Total: 0


0.1.15 - 2020-09-30 19:11:29

"Deploy to CocoaPods" on release created GitHub Action.

0.1.6 - 2020-09-30 00:50:42

"Deploy to CocoaPods" GitHub Action test.

0.1.5 - 2020-09-27 02:35:52

Swift Package and CocoaPod with Pod integration Project.

0.1.3 - 2020-09-26 20:10:48

Xcode 12 build.

- 2017-08-04 20:43:02

- 2017-07-30 22:33:02