Use Array shorthand syntactic sugar
This commit is contained in:
parent
347691d331
commit
c4f0749f1c
|
@ -15,7 +15,7 @@ import Swift
|
|||
import ElementaryCyclesSearch
|
||||
|
||||
extension ElementaryCyclesSearch {
|
||||
static func toArray(elementaryCycles: Array<Array<Node>>) -> [[Node]] {
|
||||
static func toArray(elementaryCycles: [[Node]]) -> [[Node]] {
|
||||
var cycles = [[Node]]()
|
||||
for vector in elementaryCycles {
|
||||
var cycle = [Node]()
|
||||
|
|
|
@ -39,7 +39,7 @@ extension Matrix where Element == Int {
|
|||
let list = Matrix<Int>(adjacencyMatrix.reservedLength)
|
||||
|
||||
for i in 0 ..< adjacencyMatrix.reservedLength {
|
||||
var v = Array<Int>()
|
||||
var v = [Int]()
|
||||
for j in 0 ..< adjacencyMatrix[i].reservedLength {
|
||||
if let isAdjacent = adjacencyMatrix[i]?[j], isAdjacent {
|
||||
v.append(j)
|
||||
|
|
|
@ -77,7 +77,7 @@ class StrongConnectedComponents {
|
|||
private var visited: Vector<Bool>!
|
||||
|
||||
/** Helpattribute for finding scc's */
|
||||
private var stack: Array<Int>!
|
||||
private var stack: [Int]!
|
||||
|
||||
/** Helpattribute for finding scc's */
|
||||
private var lowlink: Vector<Int>!
|
||||
|
@ -89,7 +89,7 @@ class StrongConnectedComponents {
|
|||
private var strongConnectedComponentsCounter = 0;
|
||||
|
||||
/** Helpattribute for finding scc's */
|
||||
private var currentStrongConnectedComponents: Array<Array<Int>>!
|
||||
private var currentStrongConnectedComponents: [[Int]]!
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -116,8 +116,8 @@ class StrongConnectedComponents {
|
|||
lowlink = Vector<Int>(self.adjacencyListOriginal.reservedLength)
|
||||
number = Vector<Int>(self.adjacencyListOriginal.reservedLength)
|
||||
visited = Vector<Bool>(self.adjacencyListOriginal.reservedLength)
|
||||
stack = Array<Int>()
|
||||
currentStrongConnectedComponents = Array<Array<Int>>()
|
||||
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<Int>()
|
||||
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<Int>? {
|
||||
private func getLowestIdComponent() -> [Int]? {
|
||||
var min = adjacencyList.reservedLength;
|
||||
var currScc: Array<Int>?
|
||||
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<Int>?) -> 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<Int>()
|
||||
var strongConnectedComponents = [Int]()
|
||||
|
||||
repeat {
|
||||
guard let popped = stack.popLast() else { break }
|
||||
|
|
|
@ -42,13 +42,13 @@ import Swift
|
|||
*/
|
||||
public class ElementaryCyclesSearch<Node> {
|
||||
/** List of cycles */
|
||||
private var cycles: Array<Array<Node>>
|
||||
private var cycles: [[Node]]
|
||||
|
||||
/** Adjacency-list of graph */
|
||||
private var adjacencyList: AdjacencyList
|
||||
|
||||
/** Graphnodes */
|
||||
private var graphNodes: Array<Node>
|
||||
private var graphNodes: [Node]
|
||||
|
||||
/** Blocked nodes, used by the algorithm of Johnson */
|
||||
private var blocked: Vector<Bool>
|
||||
|
@ -57,7 +57,7 @@ public class ElementaryCyclesSearch<Node> {
|
|||
private var B: Matrix<Int>
|
||||
|
||||
/** Stack for nodes, used by the algorithm of Johnson */
|
||||
private var stack: Array<Int>
|
||||
private var stack: [Int]
|
||||
|
||||
/**
|
||||
* Returns List::List::Object with the Lists of nodes of all elementary
|
||||
|
@ -70,7 +70,7 @@ public class ElementaryCyclesSearch<Node> {
|
|||
*
|
||||
* @return List::List::Object with the Lists of the elementary cycles.
|
||||
*/
|
||||
public static func getElementaryCycles(adjacencyMatrix: AdjacencyMatrix, graphNodes: Array<Node>) -> Array<Array<Node>> {
|
||||
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<Node> {
|
|||
* build sets of the elementary cycles containing the objects of the original
|
||||
* graph-representation
|
||||
*/
|
||||
private init(adjacencyMatrix: AdjacencyMatrix, graphNodes: Array<Node>) {
|
||||
private init(adjacencyMatrix: AdjacencyMatrix, graphNodes: [Node]) {
|
||||
self.graphNodes = graphNodes;
|
||||
self.adjacencyList = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjacencyMatrix)
|
||||
cycles = Array<Array<Node>>()
|
||||
cycles = [[Node]]()
|
||||
blocked = Vector<Bool>(adjacencyList.reservedLength)
|
||||
B = Matrix<Int>(adjacencyList.reservedLength)
|
||||
stack = Array<Int>()
|
||||
stack = [Int]()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +98,7 @@ public class ElementaryCyclesSearch<Node> {
|
|||
*
|
||||
* @return List::List::Object with the Lists of the elementary cycles.
|
||||
*/
|
||||
private func getElementaryCycles() -> Array<Array<Node>> {
|
||||
private func getElementaryCycles() -> [[Node]] {
|
||||
let sccs = StrongConnectedComponents(adjacencyList: adjacencyList)
|
||||
var s = 0
|
||||
|
||||
|
@ -142,7 +142,7 @@ public class ElementaryCyclesSearch<Node> {
|
|||
let w = adjacencyList[v].get(i)
|
||||
// found cycle
|
||||
if w == s {
|
||||
var cycle = Array<Node>()
|
||||
var cycle = [Node]()
|
||||
for j in 0 ..< stack.count {
|
||||
let index = stack[j]
|
||||
let node = graphNodes[index] // WARNING guard
|
||||
|
|
|
@ -26,7 +26,7 @@ import ElementaryCyclesSearch
|
|||
|
||||
typealias Node = String
|
||||
|
||||
private func printCycles(_ cycles: Array<Array<Node>>) {
|
||||
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<Array<Node>>) {
|
|||
}
|
||||
}
|
||||
|
||||
let nodes: Array<Node> = {
|
||||
var vector = Array<Node>()
|
||||
let nodes: [Node] = {
|
||||
var vector = [Node]()
|
||||
for i in 0 ..< 10 {
|
||||
vector.append("Node \(i)")
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ final class ElementaryCyclesSearchTests: XCTestCase {
|
|||
|
||||
private typealias Node = String
|
||||
|
||||
private var nodes: Array<Node> {
|
||||
var nodes = Array<Node>()
|
||||
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<Node>) -> Array<Array<Node>>)!
|
||||
private var sut: ((AdjacencyMatrix, [Node]) -> [[Node]])!
|
||||
|
||||
private func prettify(cycles: Array<Array<Node>>) -> String {
|
||||
private func prettify(cycles: [[Node]]) -> String {
|
||||
var description = ""
|
||||
for i in 0 ..< cycles.count {
|
||||
let cycle = cycles[i]
|
||||
|
|
|
@ -7,8 +7,8 @@ final class ElementaryCyclesSearchShould: XCTestCase {
|
|||
|
||||
private typealias Node = String
|
||||
|
||||
private var nodes: Array<Node> {
|
||||
var nodes = Array<Node>()
|
||||
private var nodes: [Node] {
|
||||
var nodes = [Node]()
|
||||
for i in 0 ..< 10 {
|
||||
nodes.append("Node \(i)")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue