SortedArray

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 that keeps itself sorted.

Instance Properties

  • Underlying storage of elements contained herein.

    Declaration

    Swift

    public var base: [Element]

Initializers

  • Create an empty SortedArray.

    Declaration

    Swift

    public init()
  • Creates an empty SortedArray type with preallocated space for at least the specified number of elements.

    Declaration

    Swift

    public init(minimumCapacity: Int)
  • Create a SortedArray with the given sequence of elements.

    Declaration

    Swift

    public init<S>(_ elements: S) where Element == S.Element, S : Sequence
  • Create a SortedArray with the given collection of presorted elements.

    Warning

    You must be certain that presorted is sorted, otherwise undefined behavior is certain.

    Declaration

    Swift

    public init<C>(presorted: C) where Element == C.Element, C : Collection
  • Create a SortedArray with the given array of presorted elements.

    Warning

    You must be certain that presorted is sorted, otherwise undefined behavior is certain.

    Declaration

    Swift

    public init(presorted: [Element])
  • Creates a SortedArray with the contents of another one.

    Declaration

    Swift

    public init(_ sorted: SortedArray)

Instance Methods

  • Remove the given element, if it is contained herein.

    Todo

    Make throws instead of returning silently.

    Declaration

    Swift

    public mutating func remove(_ element: Element)
  • Insert the given element.

    Complexity

    O(n)

    Declaration

    Swift

    public mutating func insert(_ element: Element)
  • Insert the contents of another sequence of T.

    Declaration

    Swift

    public mutating func insert<S>(contentsOf elements: S) where Element == S.Element, S : Sequence
  • Reserves the amount of memory to store the given minimumCapacity of elements.

    Declaration

    Swift

    public mutating func reserveCapacity(_ minimumCapacity: Int)
  • Appends the given element.

    Warning

    This element must be greater or equal to the current maximum, otherwise there will be undefined behavior ahead.

    Declaration

    Swift

    public mutating func append(guaranteedMax element: Element)
  • Declaration

    Swift

    public func index(of element: Element) -> Int?

    Return Value

    Index for the given element, if it exists. Otherwise, nil.

  • Declaration

    Swift

    public subscript(bounds: Range<Base.Index>) -> Slice<Base> { get }

    Return Value

    The slice of the SortedArray for the given bounds.

Additive

  • Declaration

    Swift

    public static var zero: SortedArray { get }

    Return Value

    Empty SortedArray.

  • Declaration

    Swift

    public static func + <T>(lhs: SortedArray<T>, rhs: SortedArray<T>) -> SortedArray<T> where T : Comparable

    Return Value

    SortedArray with the contents of two SortedArray values.

Monoid

  • Declaration

    Swift

    public static var identity: SortedArray<Element> { get }

    Return Value

    Empty SortedArray.

  • Declaration

    Swift

    public static func <> (lhs: SortedArray<Element>, rhs: SortedArray<Element>)
        -> SortedArray<Element>

    Return Value

    Composition of two of the same Semigroup type values.

ExpressibleByArrayLiteral

  • Declaration

    Swift

    public init(arrayLiteral elements: Element...)

    Return Value

    Create a SortedArray with an array literal.