Skip to content

Commit 8d19c04

Browse files
committed
Release 1.4.1
1 parent c5af0a1 commit 8d19c04

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.4.1
2+
- Fixed a bug in `removeAllEdges()` and added a test for it
3+
14
### 1.4.0
25
- Added a Minimum Spanning Tree Fuction `mst()` based on Jarnik's Algorithm (aka Prim's Algorithm)
36
- Simplified Dijkstra's Algorithm implementation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Use the CocoaPod `SwiftGraph`.
1717
Add the following to your `Cartfile`:
1818

1919
```
20-
github "davecom/SwiftGraph" ~> 1.4.0
20+
github "davecom/SwiftGraph" ~> 1.4.1
2121
```
2222

2323
### Swift Package Manager (SPM)

Sources/Graph.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ open class Graph<V: Equatable>: CustomStringConvertible, Sequence, Collection {
162162
/// - parameter to: The ending vertex's index.
163163
/// - parameter bidirectional: Remove edges coming back (to -> from)
164164
public func removeAllEdges(from: Int, to: Int, bidirectional: Bool = true) {
165-
for i in 0..<edges[from].count where edges[from][i].v == to {
165+
for (i, edge) in edges[from].enumerated().reversed() where edge.v == to {
166166
edges[from].remove(at: i)
167167
}
168168

169169
if bidirectional {
170-
for i in 0..<edges[to].count where edges[to][i].v == from {
170+
for (i, edge) in edges[to].enumerated().reversed() where edge.v == from {
171171
edges[to].remove(at: i)
172172
}
173173
}

SwiftGraph.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SwiftGraph'
3-
s.version = '1.4.0'
3+
s.version = '1.4.1'
44
s.license = { :type => "Apache License, Version 2.0", :file => "LICENSE" }
55
s.summary = 'A Graph Data Structure in Pure Swift'
66
s.homepage = 'https://github.com/davecom/SwiftGraph'

SwiftGraphTests/SwiftGraphTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ class SwiftGraphTests: XCTestCase {
8181
XCTAssertEqual(g[2], "Miami", "Expected result at vertex 2")
8282
}
8383

84+
func testRemoveAllEdges() {
85+
let graph = UnweightedGraph(vertices: ["0", "1", "2", "3", "4", "5", "6"])
86+
87+
graph.addEdge(from: "0", to: "1", directed: false)
88+
graph.addEdge(from: "1", to: "2", directed: false)
89+
graph.addEdge(from: "2", to: "3", directed: false)
90+
graph.addEdge(from: "3", to: "2", directed: false)
91+
graph.addEdge(from: "3", to: "4", directed: false)
92+
graph.addEdge(from: "4", to: "5", directed: false)
93+
94+
graph.removeAllEdges(from: 2, to: 3, bidirectional: true)
95+
XCTAssertFalse(graph.edgeExists(from: 2, to: 3))
96+
XCTAssertFalse(graph.edgeExists(from: 3, to: 2))
97+
}
98+
8499
//func testPerformanceExample() {
85100
// This is an example of a performance test case.
86101
// self.measureBlock() {

0 commit comments

Comments
 (0)