Linear
-
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.
See morematrix[row: 0, column: 1] = 1 // => 0,1,0 // 0,0,0 // 0,0,0
Declaration
Swift
public struct Matrix<Element>
extension Matrix: SequenceWrapping
extension Matrix: CustomStringConvertible
extension Matrix: Equatable where Element: Equatable
-
The
See moreLinkedList
.Declaration
Swift
public enum LinkedList<Element>
extension LinkedList: Collection
extension LinkedList: ExpressibleByArrayLiteral
extension LinkedList: Equatable where Element: Equatable
-
Stack structure.
See moreDeclaration
Swift
public struct Stack<Element>
extension Stack: Collection
extension Stack: BidirectionalCollection
extension Stack: ExpressibleByArrayLiteral
extension Stack: CustomStringConvertible
extension Stack: Additive
extension Stack: Monoid
extension Stack: Equatable where Element: Equatable
-
First-in-first-out linear data structure.
Remark
Consider using two linked lists instead of anArray
as the internal storage.Array
givesO(*n*)
performance forremove(at:)
, which is used bydequeue
.Declaration
Swift
public struct Queue<Element>
-
See moreArray
that keeps itself sorted.Declaration
Swift
public struct SortedArray <Element: Comparable>: RandomAccessCollectionWrapping, SortedCollectionWrapping
extension SortedArray: Equatable
extension SortedArray: Additive
extension SortedArray: Monoid
extension SortedArray: ExpressibleByArrayLiteral
extension SortedArray: Hashable where Element: Hashable
-
Array-like structure that allows retrieval of elements at indices outside of the bounds of the internal storage.
Example Usage
See morelet loop: CircularArray = [0,1,2,3,4,5] loop[circular: 6] // => 0 loop[from: 2, through: 7] // => [2,3,4,5,0,1]
Declaration
Swift
public struct CircularArray<Element>
extension CircularArray: RandomAccessCollectionWrapping
extension CircularArray: BidirectionalCollection
extension CircularArray: RangeReplaceableCollection
extension CircularArray: ExpressibleByArrayLiteral
extension CircularArray: Equatable where Element: Equatable