Linear
-
Two-dimensional matrix with user-definable dimensions, parameterized over the generic
Element.Example Usage
It is quite pleasant to fill a new
Matrixvalue.let matrix = Matrix(height: 3, width: 3, initial: 0) // => 0,0,0 // 0,0,0 // 0,0,0You 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] // => 0You 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,0Declaration
Swift
public struct Matrix<Element>extension Matrix: SequenceWrappingextension Matrix: CustomStringConvertibleextension Matrix: Equatable where Element: Equatable -
The
See moreLinkedList.Declaration
Swift
public enum LinkedList<Element>extension LinkedList: Collectionextension LinkedList: ExpressibleByArrayLiteralextension LinkedList: Equatable where Element: Equatable -
Stack structure.
See moreDeclaration
Swift
public struct Stack<Element>extension Stack: Collectionextension Stack: BidirectionalCollectionextension Stack: ExpressibleByArrayLiteralextension Stack: CustomStringConvertibleextension Stack: Additiveextension Stack: Monoidextension Stack: Equatable where Element: Equatable -
First-in-first-out linear data structure.
See moreRemark
Consider using two linked lists instead of anArrayas the internal storage.ArraygivesO(*n*)performance forremove(at:), which is used bydequeue.Declaration
Swift
public struct Queue<Element> -
See moreArraythat keeps itself sorted.Declaration
Swift
public struct SortedArray <Element: Comparable>: RandomAccessCollectionWrapping, SortedCollectionWrappingextension SortedArray: Equatableextension SortedArray: Additiveextension SortedArray: Monoidextension SortedArray: ExpressibleByArrayLiteralextension 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: RandomAccessCollectionWrappingextension CircularArray: BidirectionalCollectionextension CircularArray: RangeReplaceableCollectionextension CircularArray: ExpressibleByArrayLiteralextension CircularArray: Equatable where Element: Equatable
View on GitHub
Install in Dash
Linear Reference