diff --git a/Sources/ElementaryCycles/Private/ElementaryCyclesSearch+toArray.swift b/Sources/ElementaryCycles/Private/ElementaryCyclesSearch+toArray.swift index 44a351e..55df767 100644 --- a/Sources/ElementaryCycles/Private/ElementaryCyclesSearch+toArray.swift +++ b/Sources/ElementaryCycles/Private/ElementaryCyclesSearch+toArray.swift @@ -15,7 +15,7 @@ import Swift import ElementaryCyclesSearch extension ElementaryCyclesSearch { - static func toArray(elementaryCycles: Array>) -> [[Node]] { + static func toArray(elementaryCycles: [[Node]]) -> [[Node]] { var cycles = [[Node]]() for vector in elementaryCycles { var cycle = [Node]() diff --git a/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift b/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift index cfc7c7e..12f8adf 100644 --- a/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift +++ b/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift @@ -39,7 +39,7 @@ extension Matrix where Element == Int { let list = Matrix(adjacencyMatrix.reservedLength) for i in 0 ..< adjacencyMatrix.reservedLength { - var v = Array() + var v = [Int]() for j in 0 ..< adjacencyMatrix[i].reservedLength { if let isAdjacent = adjacencyMatrix[i]?[j], isAdjacent { v.append(j) diff --git a/Sources/ElementaryCyclesSearch/Private/StrongConnectedComponents.swift b/Sources/ElementaryCyclesSearch/Private/StrongConnectedComponents.swift index 9c60e69..add272f 100644 --- a/Sources/ElementaryCyclesSearch/Private/StrongConnectedComponents.swift +++ b/Sources/ElementaryCyclesSearch/Private/StrongConnectedComponents.swift @@ -77,7 +77,7 @@ class StrongConnectedComponents { private var visited: Vector! /** Helpattribute for finding scc's */ - private var stack: Array! + private var stack: [Int]! /** Helpattribute for finding scc's */ private var lowlink: Vector! @@ -89,7 +89,7 @@ class StrongConnectedComponents { private var strongConnectedComponentsCounter = 0; /** Helpattribute for finding scc's */ - private var currentStrongConnectedComponents: Array>! + private var currentStrongConnectedComponents: [[Int]]! /** * Constructor. @@ -116,8 +116,8 @@ class StrongConnectedComponents { lowlink = Vector(self.adjacencyListOriginal.reservedLength) number = Vector(self.adjacencyListOriginal.reservedLength) visited = Vector(self.adjacencyListOriginal.reservedLength) - stack = Array() - currentStrongConnectedComponents = Array>() + stack = [Int]() + currentStrongConnectedComponents = [[Int]]() makeAdjacencyListSubgraph(node: node); @@ -153,7 +153,7 @@ class StrongConnectedComponents { adjacencyList = AdjacencyList(adjacencyListOriginal.reservedLength, 0) for i in node ..< adjacencyList.reservedLength { - var successors = Array() + var successors = [Int]() for j in 0 ..< self.adjacencyListOriginal[i].reservedLength { guard let original = adjacencyListOriginal[i]?[j] else { continue } if original >= node { @@ -176,9 +176,9 @@ class StrongConnectedComponents { * * @return Vector::Integer of the strongConnectedComponents containing the lowest nodenumber */ - private func getLowestIdComponent() -> Array? { + private func getLowestIdComponent() -> [Int]? { var min = adjacencyList.reservedLength; - var currScc: Array? + var currScc: [Int]? for i in 0 ..< currentStrongConnectedComponents.count { let strongConnectedComponents = currentStrongConnectedComponents[i] @@ -199,7 +199,7 @@ class StrongConnectedComponents { * strong connected component with least vertex in the currently viewed * subgraph */ - private func getAdjList(nodes: Array?) -> AdjacencyList? { + private func getAdjList(nodes: [Int]?) -> AdjacencyList? { guard let nodes = nodes else { return nil } let lowestIdAdjacencyList = AdjacencyList(adjacencyList.reservedLength) for i in 0 ..< lowestIdAdjacencyList.reservedLength { @@ -246,7 +246,7 @@ class StrongConnectedComponents { // found strongConnectedComponents if (lowlink[root] == number[root]) && (stack.count > 0) { var next = -1; - var strongConnectedComponents = Array() + var strongConnectedComponents = [Int]() repeat { guard let popped = stack.popLast() else { break } diff --git a/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift b/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift index 19b2aa5..2a514d3 100644 --- a/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift +++ b/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift @@ -42,13 +42,13 @@ import Swift */ public class ElementaryCyclesSearch { /** List of cycles */ - private var cycles: Array> + private var cycles: [[Node]] /** Adjacency-list of graph */ private var adjacencyList: AdjacencyList /** Graphnodes */ - private var graphNodes: Array + private var graphNodes: [Node] /** Blocked nodes, used by the algorithm of Johnson */ private var blocked: Vector @@ -57,7 +57,7 @@ public class ElementaryCyclesSearch { private var B: Matrix /** Stack for nodes, used by the algorithm of Johnson */ - private var stack: Array + private var stack: [Int] /** * Returns List::List::Object with the Lists of nodes of all elementary @@ -70,7 +70,7 @@ public class ElementaryCyclesSearch { * * @return List::List::Object with the Lists of the elementary cycles. */ - public static func getElementaryCycles(adjacencyMatrix: AdjacencyMatrix, graphNodes: Array) -> Array> { + public static func getElementaryCycles(adjacencyMatrix: AdjacencyMatrix, graphNodes: [Node]) -> [[Node]] { let ecs = ElementaryCyclesSearch(adjacencyMatrix: adjacencyMatrix, graphNodes: graphNodes) return ecs.getElementaryCycles() } @@ -83,13 +83,13 @@ public class ElementaryCyclesSearch { * build sets of the elementary cycles containing the objects of the original * graph-representation */ - private init(adjacencyMatrix: AdjacencyMatrix, graphNodes: Array) { + private init(adjacencyMatrix: AdjacencyMatrix, graphNodes: [Node]) { self.graphNodes = graphNodes; self.adjacencyList = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjacencyMatrix) - cycles = Array>() + cycles = [[Node]]() blocked = Vector(adjacencyList.reservedLength) B = Matrix(adjacencyList.reservedLength) - stack = Array() + stack = [Int]() } /** @@ -98,7 +98,7 @@ public class ElementaryCyclesSearch { * * @return List::List::Object with the Lists of the elementary cycles. */ - private func getElementaryCycles() -> Array> { + private func getElementaryCycles() -> [[Node]] { let sccs = StrongConnectedComponents(adjacencyList: adjacencyList) var s = 0 @@ -142,7 +142,7 @@ public class ElementaryCyclesSearch { let w = adjacencyList[v].get(i) // found cycle if w == s { - var cycle = Array() + var cycle = [Node]() for j in 0 ..< stack.count { let index = stack[j] let node = graphNodes[index] // WARNING guard diff --git a/Sources/ElementaryCyclesSearchExample/main.swift b/Sources/ElementaryCyclesSearchExample/main.swift index 8a415db..983c77e 100644 --- a/Sources/ElementaryCyclesSearchExample/main.swift +++ b/Sources/ElementaryCyclesSearchExample/main.swift @@ -26,7 +26,7 @@ import ElementaryCyclesSearch typealias Node = String -private func printCycles(_ cycles: Array>) { +private func printCycles(_ cycles: [[Node]]) { for i in 0 ..< cycles.count { let cycle = cycles[i] for j in 0 ..< cycle.count { @@ -41,8 +41,8 @@ private func printCycles(_ cycles: Array>) { } } -let nodes: Array = { - var vector = Array() +let nodes: [Node] = { + var vector = [Node]() for i in 0 ..< 10 { vector.append("Node \(i)") } diff --git a/Tests/ElementaryCyclesSearchTests/ElementaryCyclesSearchTests.swift b/Tests/ElementaryCyclesSearchTests/ElementaryCyclesSearchTests.swift index 4ef3191..2120b35 100644 --- a/Tests/ElementaryCyclesSearchTests/ElementaryCyclesSearchTests.swift +++ b/Tests/ElementaryCyclesSearchTests/ElementaryCyclesSearchTests.swift @@ -6,8 +6,8 @@ final class ElementaryCyclesSearchTests: XCTestCase { private typealias Node = String - private var nodes: Array { - var nodes = Array() + private var nodes: [Node] { + var nodes = [Node]() for i in 0 ..< 10 { nodes.append("Node \(i)") } @@ -29,9 +29,9 @@ final class ElementaryCyclesSearchTests: XCTestCase { matrix[6][1] = true } - private var sut: ((AdjacencyMatrix, Array) -> Array>)! + private var sut: ((AdjacencyMatrix, [Node]) -> [[Node]])! - private func prettify(cycles: Array>) -> String { + private func prettify(cycles: [[Node]]) -> String { var description = "" for i in 0 ..< cycles.count { let cycle = cycles[i] diff --git a/Tests/ElementaryCyclesTests/ElementaryCyclesSearchShould.swift b/Tests/ElementaryCyclesTests/ElementaryCyclesSearchShould.swift index 1578903..a1cceca 100644 --- a/Tests/ElementaryCyclesTests/ElementaryCyclesSearchShould.swift +++ b/Tests/ElementaryCyclesTests/ElementaryCyclesSearchShould.swift @@ -7,8 +7,8 @@ final class ElementaryCyclesSearchShould: XCTestCase { private typealias Node = String - private var nodes: Array { - var nodes = Array() + private var nodes: [Node] { + var nodes = [Node]() for i in 0 ..< 10 { nodes.append("Node \(i)") }