Matrix

public struct Matrix<Element>
extension Matrix: SequenceWrapping
extension Matrix: CustomStringConvertible
extension Matrix: Equatable where Element: Equatable

Two-dimensional matrix with user-definable dimensions, parameterized over the generic Element.

Example Usage

It is quite pleasant to fill a new Matrix value.

let matrix = Matrix(height: 3, width: 3, initial: 0)
// => 0,0,0
//    0,0,0
//    0,0,0

You can ask what the value is at a given row and column.

Warning: Your program will crash if the row or column is invalid — so, be careful!

matrix[row: 1, column: 2] // => 0

You can also set the value at the given row and column.

matrix[row: 0, column: 1] = 1
// => 0,1,0
//    0,0,0
//    0,0,0

Instance Properties

  • Declaration

    Swift

    public var rows: [[Element]] { get }

    Return Value

    Array of rows.

  • Declaration

    Swift

    public var columns: [[Element]] { get }

    Return Value

    Array of columns.

Initializers

  • Create a Matrix with the given dimensions and the given initial value.

    Declaration

    Swift

    public init(height rowCount: Int, width columnCount: Int, initial: Element)

Subscripts

  • Get and set the value for the given row and column, if these are valid indices. Otherwise, nil is returned or nothing is set.

    Declaration

    Swift

    public subscript(row: Int, column: Int) -> Element { get set }
  • Get and set an row of values.

    Declaration

    Swift

    public subscript(row row: Int) -> [Element] { get set }
  • Get and set a column of values.

    Declaration

    Swift

    public subscript(column column: Int) -> [Element] { get set }

SequenceWrapping

  • Declaration

    Swift

    public var base: [Element] { get }

    Return Value

    Underlying Collection.

CustomStringConvertible

  • Printed description of Matrix.

    Declaration

    Swift

    public var description: String { get }