diff --git a/Sources/ElementaryCycles/Private/AdjacencyMatrix+getAdjacencyMatrix.swift b/Sources/ElementaryCycles/Private/AdjacencyMatrix+getAdjacencyMatrix.swift index c93f756..f367ae0 100644 --- a/Sources/ElementaryCycles/Private/AdjacencyMatrix+getAdjacencyMatrix.swift +++ b/Sources/ElementaryCycles/Private/AdjacencyMatrix+getAdjacencyMatrix.swift @@ -14,7 +14,7 @@ import Swift import ElementaryCyclesSearch -extension Matrix where Element == Bool { +extension Matrix2D where Element == Bool { enum Error: Swift.Error { case indexNotFound(node: AnyHashable, nodes: [AnyHashable]) } diff --git a/Sources/ElementaryCycles/Private/AdjacencyMatrix+getNodes.swift b/Sources/ElementaryCycles/Private/AdjacencyMatrix+getNodes.swift index 0e9718c..836b597 100644 --- a/Sources/ElementaryCycles/Private/AdjacencyMatrix+getNodes.swift +++ b/Sources/ElementaryCycles/Private/AdjacencyMatrix+getNodes.swift @@ -14,7 +14,7 @@ import Swift import ElementaryCyclesSearch -extension Matrix where Element == Bool { +extension Matrix2D where Element == Bool { static func getNodes(graph: [Node: [Node]], sort: ((Node, Node) -> Bool)?) -> [Node] { var nodes = [Node]() for (node, adjacentNodes) in graph { diff --git a/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift b/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift index 12f8adf..3c516ab 100644 --- a/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift +++ b/Sources/ElementaryCyclesSearch/Private/AdjacencyList+getAdjacencyList.swift @@ -24,7 +24,7 @@ import Swift * @version 1.0, 26.08.2006 * */ -extension Matrix where Element == Int { +extension Matrix2D where Element == Int { /** * Calculates a adjacency-list for a given array of an adjacency-matrix. * @@ -35,8 +35,8 @@ extension Matrix where Element == Int { * adjacency, the second dimension represents the indicies of those nodes, * that are direct successornodes of the node. */ - static func getAdjacencyList(adjacencyMatrix: AdjacencyMatrix) -> Matrix { - let list = Matrix(adjacencyMatrix.reservedLength) + static func getAdjacencyList(adjacencyMatrix: AdjacencyMatrix) -> Matrix2D { + let list = Matrix2D(adjacencyMatrix.reservedLength) for i in 0 ..< adjacencyMatrix.reservedLength { var v = [Int]() diff --git a/Sources/ElementaryCyclesSearch/Private/AdjacencyList.swift b/Sources/ElementaryCyclesSearch/Private/AdjacencyList.swift index 1669c16..6e52f7f 100644 --- a/Sources/ElementaryCyclesSearch/Private/AdjacencyList.swift +++ b/Sources/ElementaryCyclesSearch/Private/AdjacencyList.swift @@ -16,4 +16,4 @@ import Swift -typealias AdjacencyList = Matrix +typealias AdjacencyList = Matrix2D diff --git a/Sources/ElementaryCyclesSearch/Public/AdjacencyMatrix.swift b/Sources/ElementaryCyclesSearch/Public/AdjacencyMatrix.swift index cf3fbe4..a4b4776 100644 --- a/Sources/ElementaryCyclesSearch/Public/AdjacencyMatrix.swift +++ b/Sources/ElementaryCyclesSearch/Public/AdjacencyMatrix.swift @@ -16,9 +16,9 @@ import Swift -public typealias AdjacencyMatrix = Matrix +public typealias AdjacencyMatrix = Matrix2D -extension Matrix where Element == Bool { +extension Matrix2D where Element == Bool { public convenience init(_ reservedRows: Int, _ reservedColumns: Int = 0, builder: (AdjacencyMatrix) -> Void) { self.init(reservedRows, reservedColumns) builder(self) diff --git a/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift b/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift index f4dd71a..807d5f3 100644 --- a/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift +++ b/Sources/ElementaryCyclesSearch/Public/ElementaryCyclesSearch.swift @@ -54,7 +54,7 @@ public class ElementaryCyclesSearch { private var blocked: Vector /** B-Lists, used by the algorithm of Johnson */ - private var B: Matrix + private var B: Matrix2D /** Stack for nodes, used by the algorithm of Johnson */ private var stack: [Int] @@ -88,7 +88,7 @@ public class ElementaryCyclesSearch { self.adjacencyList = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjacencyMatrix) cycles = [[Node]]() blocked = Vector(adjacencyList.reservedLength) - B = Matrix(adjacencyList.reservedLength) + B = Matrix2D(adjacencyList.reservedLength) stack = [Int]() } diff --git a/Sources/ElementaryCyclesSearch/Public/Vector/Matrix+Sequence.swift b/Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D+Sequence.swift similarity index 85% rename from Sources/ElementaryCyclesSearch/Public/Vector/Matrix+Sequence.swift rename to Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D+Sequence.swift index 84b9c71..659ce7a 100644 --- a/Sources/ElementaryCyclesSearch/Public/Vector/Matrix+Sequence.swift +++ b/Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D+Sequence.swift @@ -13,15 +13,15 @@ import Swift -public struct MatrixIterator: IteratorProtocol { - private let matrix: Matrix +public struct Matrix2DIterator: IteratorProtocol { + private let matrix: Matrix2D private var currentIndex = -1 private var currentIterator: VectorIterator? - - fileprivate init(matrix: Matrix) { + + fileprivate init(matrix: Matrix2D) { self.matrix = matrix } - + mutating public func next() -> Element? { if let element = currentIterator?.next() { return element @@ -34,8 +34,8 @@ public struct MatrixIterator: IteratorProtocol { } } -extension Matrix: Sequence { - public func makeIterator() -> MatrixIterator { - return MatrixIterator(matrix: self) +extension Matrix2D: Sequence { + public func makeIterator() -> Matrix2DIterator { + return Matrix2DIterator(matrix: self) } } diff --git a/Sources/ElementaryCyclesSearch/Public/Vector/Matrix.swift b/Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D.swift similarity index 90% rename from Sources/ElementaryCyclesSearch/Public/Vector/Matrix.swift rename to Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D.swift index 0b44a51..7da7d74 100644 --- a/Sources/ElementaryCyclesSearch/Public/Vector/Matrix.swift +++ b/Sources/ElementaryCyclesSearch/Public/Vector/Matrix2D.swift @@ -13,7 +13,7 @@ import Swift -public final class Matrix { +public final class Matrix2D { private var vector: Vector> public subscript(_ row: Int) -> Vector! { @@ -24,14 +24,14 @@ public final class Matrix { vector[row] = newValue } } - + public init(_ reservedRows: Int, _ reservedColumns: Int = 0) { self.vector = Vector>(reservedRows) for i in 0 ..< reservedLength { vector[i] = Vector(reservedColumns) } } - + public convenience init(rows: [[Element]]) { var reservedColumns = 0 for row in rows { @@ -42,26 +42,26 @@ public final class Matrix { self[offset] = Vector(array: row, reservedLength: reservedColumns) } } - + public var reservedLength: Int { return vector.reservedLength } } -extension Matrix: CustomDebugStringConvertible { +extension Matrix2D: CustomDebugStringConvertible { public var debugDescription: String { return vector.debugDescription } } -extension Matrix: CustomStringConvertible { +extension Matrix2D: CustomStringConvertible { public var description: String { return vector.description } } -extension Matrix: Equatable where Element: Equatable { - public static func == (lhs: Matrix, rhs: Matrix) -> Bool { +extension Matrix2D: Equatable where Element: Equatable { + public static func == (lhs: Matrix2D, rhs: Matrix2D) -> Bool { guard lhs.reservedLength == rhs.reservedLength else { return false } for index in 0 ..< lhs.reservedLength { guard lhs[index] == rhs[index] else { return false } diff --git a/Sources/ElementaryCyclesSearch/Public/Vector/Vector.swift b/Sources/ElementaryCyclesSearch/Public/Vector/Vector.swift index e5da1f8..01089b2 100644 --- a/Sources/ElementaryCyclesSearch/Public/Vector/Vector.swift +++ b/Sources/ElementaryCyclesSearch/Public/Vector/Vector.swift @@ -77,12 +77,12 @@ public final class Vector { } extension Vector where Element: Equatable { - func contains(_ element: Element) -> Bool{ + public func contains(_ element: Element) -> Bool { return array.contains(element) } @discardableResult - func remove(element: Element) -> Bool { + public func remove(element: Element) -> Bool { if let index = array.firstIndex(of: element) { array.remove(at: -index.distance(to: 0)) return true diff --git a/Tests/ElementaryCyclesSearchTests/AdjacencyListTests.swift b/Tests/ElementaryCyclesSearchTests/AdjacencyListTests.swift index ecdf470..cb8cfb4 100644 --- a/Tests/ElementaryCyclesSearchTests/AdjacencyListTests.swift +++ b/Tests/ElementaryCyclesSearchTests/AdjacencyListTests.swift @@ -16,7 +16,7 @@ final class AdjacencyListTests: XCTestCase { } } - var sut: ((AdjacencyMatrix) -> Matrix)! + var sut: ((AdjacencyMatrix) -> Matrix2D)! override func setUp() { super.setUp() diff --git a/Tests/ElementaryCyclesSearchTests/AdjacencyMatrixTests.swift b/Tests/ElementaryCyclesSearchTests/AdjacencyMatrixTests.swift index d220881..5ac8087 100644 --- a/Tests/ElementaryCyclesSearchTests/AdjacencyMatrixTests.swift +++ b/Tests/ElementaryCyclesSearchTests/AdjacencyMatrixTests.swift @@ -22,9 +22,9 @@ final class AdjacencyMatrixTests: XCTestCase { func testConvenienceInit() { let rows = [["a"],[],["b", "c"]] - let matrix = Matrix(rows: rows) - let expectedMatrix: Matrix = { - let matrix = Matrix(3, 2) + let matrix = Matrix2D(rows: rows) + let expectedMatrix: Matrix2D = { + let matrix = Matrix2D(3, 2) matrix[0][0] = "a" matrix[2][0] = "b" matrix[2][1] = "c" @@ -34,7 +34,7 @@ final class AdjacencyMatrixTests: XCTestCase { } func testSequence() { - let matrix = Matrix(4, 4) + let matrix = Matrix2D(4, 4) matrix[0][1] = 1 matrix[1][2] = 2 matrix[3][0] = 3 diff --git a/Tests/ElementaryCyclesSearchTests/StrongConnectedComponentsTests.swift b/Tests/ElementaryCyclesSearchTests/StrongConnectedComponentsTests.swift index 5dec39f..4d6810c 100644 --- a/Tests/ElementaryCyclesSearchTests/StrongConnectedComponentsTests.swift +++ b/Tests/ElementaryCyclesSearchTests/StrongConnectedComponentsTests.swift @@ -7,7 +7,7 @@ final class StrongConnectedComponentsTests: XCTestCase { func test1() { - let adjMatrix = Matrix(10, 10) { matrix in + let adjMatrix = Matrix2D(10, 10) { matrix in matrix[0][1] = true matrix[1][2] = true matrix[2][0] = true; matrix[2][6] = true @@ -20,7 +20,7 @@ final class StrongConnectedComponentsTests: XCTestCase { matrix[6][1] = true } - let adjacencyList: Matrix = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjMatrix) + let adjacencyList: Matrix2D = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjMatrix) let sccs = StrongConnectedComponents(adjacencyList: adjacencyList) var description = "" @@ -91,7 +91,7 @@ i: 9 } func test2() { - let adjMatrix: AdjacencyMatrix = Matrix(10, 10) { matrix in + let adjMatrix: AdjacencyMatrix = Matrix2D(10, 10) { matrix in matrix[0][1] = true matrix[1][2] = true matrix[2][0] = true @@ -106,7 +106,7 @@ i: 9 matrix[9][6] = true } - let adjacencyList: Matrix = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjMatrix) + let adjacencyList: Matrix2D = AdjacencyList.getAdjacencyList(adjacencyMatrix: adjMatrix) let sccs = StrongConnectedComponents(adjacencyList: adjacencyList) var description = ""