LookUpTable

public struct LookUpTable<Input, Output> where Input : Comparable, Input : SignedNumeric

A lookup table for caching values that are spaced along a number line.

  • The type for the entries on this lookup table.

    Declaration

    Swift

    public typealias Entry = (input: Input, output: Output)
  • Returns the number of entries on this lookup table.

    Declaration

    Swift

    public var count: Int { get }
  • Subscripts directly into an entry on this lookup table.

    Precondition

    index >= 0 && index < self.count.

    Declaration

    Swift

    public subscript(index: Int) -> Entry { get }
  • Looks up the closest entry to a given input value.

    Declaration

    Swift

    @inlinable
    public func closestEntry(to input: Input) -> Entry?
  • Looks up the closest output to a given input value.

    Returns nil if this lookup table is empty.

    Declaration

    Swift

    @inlinable
    public func closestOutput(to input: Input) -> Output?
  • Looks up the index on table for the closest input value to input.

    Returns nil if this lookup table is empty.

    Declaration

    Swift

    @inlinable
    public func closestInputIndex(to input: Input) -> Int?