RandomAccessCollection

extension RandomAccessCollection
extension RandomAccessCollection where Iterator.Element: AnyObject
extension RandomAccessCollection where Iterator.Element: Equatable
extension RandomAccessCollection where Element == Key
  • Undocumented

    Declaration

    Swift

    public typealias OrderPredicate = (Iterator.Element, Iterator.Element) -> Bool
  • Binary search operation for quick determination where to insert a new value into a collection that will preserve the ordering of the existing elements.

    Declaration

    Swift

    public func insertionIndex(of value: Iterator.Element, predicate: OrderPredicate) -> Index

    Parameters

    value

    the value to insert

    predicate

    a closure/function that determines ordering of two elements

    Return Value

    index into the collection

Available where Iterator.Element: AnyObject

  • Obtain the index in a collection for a given object.

    Declaration

    Swift

    public func search(for value: Iterator.Element, predicate: OrderPredicate) -> Index

    Parameters

    value

    the object to look for

    Return Value

    index of the give value or endIndex if not found

  • Binary search operation which simply determines if a given value is in the collection.

    Declaration

    Swift

    public func contains(value: Iterator.Element, predicate: OrderPredicate) -> Bool

    Parameters

    value

    the value to look for

    predicate

    a closure/function that determines ordering of two elements

    Return Value

    true if element is in the collections

Available where Iterator.Element: Equatable

  • Obtain the index in a collection for a given value.

    Declaration

    Swift

    public func search(for value: Iterator.Element, predicate: OrderPredicate) -> Index

    Parameters

    value

    the value to look for

    Return Value

    index of the give value or endIndex if not found

  • Binary search operation which simply determines if a given value is in the collection.

    Declaration

    Swift

    public func contains(value: Iterator.Element, predicate: OrderPredicate) -> Bool

    Parameters

    value

    the value to look for

    predicate

    a closure/function that determines ordering of two elements

    Return Value

    true if element is in the collections

Available where Element == Key

  • Obtain the key that is touched by the given point.

    Declaration

    Swift

    func touched(by point: CGPoint) -> Key?

    Parameters

    point

    the location to consider

    Return Value

    Key instance that contains the point, or nil if none.

  • Obtain the sequence of keys that fill the given rect. Only considers the horizontal span for inclusion.

    Declaration

    Swift

    func keySpan(for rect: CGRect) -> Self.SubSequence

    Parameters

    rect

    the region to consider

    Return Value

    sequence of Key instances that are in the given region

  • Obtain the index of the key in the collection that corresponds to the given position. Performs a binary search to locate the right key.

    Declaration

    Swift

    func orderedInsertionIndex(for point: CGPoint) -> Index

    Parameters

    point

    the location to consider

    Return Value

    index where to insert