You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,14 @@
1
+
### 2.0.0
2
+
-**This is an API breaking refactor**
3
+
- This version requires Swift 4.2 (Xcode 10)
4
+
-`Graph` is now a protocol instead of a class
5
+
-`edgesToVertices()` is now a method on `Graph` instead of a free function
6
+
- The `Edge` protocol has been significantly simplifieid
7
+
-`UnweightedEdge` and `WeightedEdge` are now `Codable`
8
+
- Subclasses of `Graph``CodableUnweightedGraph` and `CodableWeightedGraph` provide serialization support to JSON and anything else `Codable` supports (thanks for the help, @yoiang)
9
+
- Experimental subclass of `UnweightedGraph`, `UniqueElementsGraph` provides a union operation and guarantees no duplicate vertices & edges in a graph (thanks @ferranpujolcamins)
10
+
- Cycle detector method that returns edges (thanks @ZevEisenberg)
11
+
1
12
### 1.5.1
2
13
- Project reorganized to support testing on Linux, just run `swift test`
3
14
-`Package.swift` updated for Swift 4 package management style
Copy file name to clipboardExpand all lines: README.md
+17-16Lines changed: 17 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ It includes copious in-source documentation, unit tests, as well as search funct
17
17
18
18
## Installation
19
19
20
-
SwiftGraph 2.0 (WIP on master) and above requires Swift 4.2 (Xcode 10). Use SwiftGraph 1.5.1 for Swift 4.1 (Xcode 9), SwiftGraph 1.4.1 for Swift 3 (Xcode 8), SwiftGraph 1.0.6 for Swift 2 (Xcode 7), and SwiftGraph 1.0.0 for Swift 1.2 (Xcode 6.3) support.
20
+
SwiftGraph 2.0 and above requires Swift 4.2 (Xcode 10). Use SwiftGraph 1.5.1 for Swift 4.1 (Xcode 9), SwiftGraph 1.4.1 for Swift 3 (Xcode 8), SwiftGraph 1.0.6 for Swift 2 (Xcode 7), and SwiftGraph 1.0.0 for Swift 1.2 (Xcode 6.3) support. SwiftGraph runs fine and is tested on Linux.
let path: [WeightedEdge<Int>] =pathDictToPath(from: cityGraph.indexOfVertex("New York")!, to: cityGraph.indexOfVertex("San Francisco")!, pathDict: pathDict)
91
-
let stops: [String] =edgesToVertices(edges: path, graph: cityGraph)
91
+
let stops: [String] =cightGraph.edgesToVertices(edges: path)
92
92
```
93
93
The shortest paths are found between various vertices in the graph using Dijkstra's algorithm.
94
94
```swift
@@ -118,17 +118,14 @@ There is a large amount of documentation in the source code using the latest App
118
118
### Edges
119
119
Edges connect the vertices in your graph to one another.
120
120
121
-
*`Edge` (Protocol) - A protocol that all edges in a graph must conform to. An edge is a connection between two vertices in the graph. The vertices are specified by their index in the graph which is an integer. Further, an edge knows if it's directed, or weighted. An edge can create a reversed version of itself.
121
+
*`Edge` (Protocol) - A protocol that all edges in a graph must conform to. An edge is a connection between two vertices in the graph. The vertices are specified by their index in the graph which is an integer.
122
122
*`UnweightedEdge` - This is a concrete implementation of `Edge` for unweighted graphs.
123
-
*`WeightedEdge` - A subclass of `UnweightedEdge` that adds weights. Weights are a generic type - they can be anything that implements `Comparable` and `Summable`. `Summable` is anything that implements the `+` operator. To add `Summable` support to a data type that already has the plus operator, simply write something like (support in SwiftGraph is already included for `Int`, `Float`, `Double`, and `String`):
124
-
```swift
125
-
extensionInt: Summable {}
126
-
```
123
+
*`WeightedEdge` - A subclass of `UnweightedEdge` that adds weights. Weights are a generic type - they can be anything that implements `Comparable`, `Numeric` and `Codable`. Typical weight types are `Int` and `Float`.
127
124
128
125
### Graphs
129
126
Graphs are the data structures at the heart of SwiftGraph. All vertices are assigned an integer index when they are inserted into a graph and it's generally faster to refer to them by their index than by the vertex's actual object.
130
127
131
-
Graphs implement the standard Swift protocols `SequenceType` (for iterating through all vertices) and `CollectionType` (for grabbing a vertex by its index through a subscript). For instance, the following example prints all vertices in a Graph on separate lines:
128
+
Graphs implement the standard Swift protocols `Collection` (for iterating through all vertices and for grabbing a vertex by its index through a subscript). For instance, the following example prints all vertices in a Graph on separate lines:
132
129
```swift
133
130
for v in g { // g is a Graph<String>
134
131
print(v)
@@ -141,7 +138,7 @@ print(g[23]) // g is a Graph<String>
141
138
142
139
Note: At this time, graphs are *not* thread-safe. However, once a graph is constructed, if you will only be doing lookups and searches through it (no removals of vertices/edges and no additions of vertices/edges) then you should be able to do that from multiple threads. A fully thread-safe graph implementation is a possible future direction.
143
140
144
-
*`Graph` - This is the base class for all graphs. Generally, you should use one of its canonical subclasses, `UnweightedGraph` or `WeightedGraph`, because they offer more functionality. The vertices in a `Graph` (defined as a generic at graph creation time) can be of any type that conforms to `Equatable`. `Graph` has methods for:
141
+
*`Graph`(Protocol) - This is the base protocol for all graphs. Generally, you should use one of its canonical class implementations, `UnweightedGraph` or `WeightedGraph`, instead of rolling your own adopter, because they offer significant built-in functionality. The vertices in a `Graph` (defined as a generic at graph creation time) can be of any type that conforms to `Equatable`. `Graph` has methods for:
145
142
* Adding a vertex
146
143
* Getting the index of a vertex
147
144
* Finding the neighbors of an index/vertex
@@ -151,8 +148,10 @@ Note: At this time, graphs are *not* thread-safe. However, once a graph is const
151
148
* Adding an edge
152
149
* Removing all edges between two indexes/vertices
153
150
* Removing a particular vertex (all other edge relationships are automatically updated at the same time (because the indices of their connections changes) so this is slow - O(v + e) where v is the number of vertices and e is the number of edges)
154
-
*`UnweightedGraph` - A subclass of `Graph` that adds convenience methods for adding and removing edges of type `UnweightedEdge`.
155
-
*`WeightedGraph` - A subclass of `Graph` that adds convenience methods for adding and removing edges of type `WeightedEdge`. `WeightedGraph` also adds a method for returning a list of tuples containing all of the neighbor vertices of an index along with their respective weights.
151
+
*`UnweightedGraph` - A generic class implementation of `Graph` that adds convenience methods for adding and removing edges of type `UnweightedEdge`. `UnweightedGraph` is generic over the type of the vertices.
152
+
*`WeightedGraph` - A generic class implementation of `Graph` that adds convenience methods for adding and removing edges of type `WeightedEdge`. `WeightedGraph` also adds a method for returning a list of tuples containing all of the neighbor vertices of an index along with their respective weights. `WeightedGraph` is generic over the types of the vertices and its weights.
153
+
*`CodableUnweightedGraph` and `CodableWeightedGraph` - Subclasses of `UnweightedGraph` and `WeightedGraph` that add support for the `Codable` protocol. Their vertex and weight types must also be `Codable`. This allows serialization of graphs to formats like JSON.
154
+
*`UniqueElementsGraph` - an experimental subclass of `UnweightedGraph` with support for union operations that ensures all vertices and edges in a graph are unique.
156
155
157
156
### Search
158
157
Search methods are defined in extensions of `Graph` and `WeightedGraph` in `Search.swift`.
@@ -172,12 +171,14 @@ An extension to `WeightedGraph` in `MST.swift` can find a minimum-spanning tree
172
171
An extension to `Graph` in `Cycles.swift` finds all of the cycles in a graph.
173
172
*`detectCycles()` - Uses an algorithm developed by Liu/Wang to find all of the cycles in a graph. Optionally, this method can take one parameter, `upToLength`, that specifies a length at which to stop searching for cycles. For instance, if `upToLength` is 3, `detectCycles()` will find all of the 1 vertex cycles (self-cycles, vertices with edges to themselves), and 3 vertex cycles (connection to another vertex and back again, present in all undirected graphs with more than 1 vertex). There is no such thing as a 2 vertex cycle.
174
173
175
-
## Authorship & License
176
-
SwiftGraph is written by David Kopec and released under the Apache License (see `LICENSE`). You can find my email address on my GitHub profile page. I encourage you to submit pull requests and open issues here on GitHub.
174
+
## Authorship, License, & Contributors
175
+
SwiftGraph is written by David Kopec and released under the Apache License (see `LICENSE`). You can find my email address on my GitHub profile page. I encourage you to submit pull requests and open issues here on GitHub.
176
+
177
+
I would like to thank all of the contributors who have helped improve SwiftGraph over the years, and have kept me motivated. Contributing to SwiftGraph, in-line with the Apache license, means also releasing your contribution under the same license as the original project. However, the Apache license is permissive, and you are free to include SwiftGraph in a commercial, closed source product as long as you give it & its author credit (in fact SwiftGraph has already found its way into several products). See `LICENSE` for details.
177
178
178
179
## Future Direction
179
180
Future directions for this project to take could include:
180
181
* More utility functions
181
-
* A thread safe subclass of `Graph`
182
+
* A thread safe implementation of `Graph`
182
183
* More extensive performance testing
183
-
*Integration with Swift serialization (`Codable` support)
0 commit comments