Tuple

public struct Tuple : Equatable, Hashable, Comparable

This type describes a tuple of values that are part of a key or a value in the database.

  • The indices that can be used to read entries from the tuple.

    Declaration

    Swift

    public typealias Index = Array<Int>.Index
  • The types of entries that can be stored in the tuple.

    See more

    Declaration

    Swift

    public enum EntryType : UInt8, Equatable
  • This initializer creates an empty tuple.

    Declaration

    Swift

    public init()
  • This method adds a value to the tuple.

    Declaration

    Swift

    public mutating func append<ValueType>(_ value: ValueType) where ValueType : TupleConvertible

    Parameters

    string

    The string to add.

  • This method adds the entries from another tuple to this tuple.

    Declaration

    Swift

    public mutating func append(contentsOf tuple: Tuple)

    Parameters

    string

    The string to add.

  • This method adds a null byte to the tuple.

    Declaration

    Swift

    public mutating func appendNullByte()
  • This method gets the tuple with this tuple’s data, but with a 0xFF byte on the end.

    This can be useful in range queries. If you want a range to include all valid tuples that start with this tuple’s data, you can have the start of the range be this tuple and the end of the range be the copy with the range byte added.

    Declaration

    Swift

    public mutating func appendRangeEndByte()
  • This method gets the tuple that comes immediately after this one, lexographically.

    Declaration

    Swift

    public func appendingNullByte() -> Tuple
  • The number of entries in the tuple.

    Declaration

    Swift

    public var count: Int { get }
  • This method gets the type of a field in this tuple.

    If the index is outside the bounds of the tuple, this will return nil.

    Declaration

    Swift

    public func type(at index: Index) -> EntryType?

    Parameters

    index

    The field we want to read.

    Return Value

    The type of the field.

  • This method reads a value from the tuple.

    If the index is outside our bounds, this will throw a ParsingError. If the entry at that index is of a different type, this will throw a ParsingError.

    Throws

    A ParsingError explaining why we can’t read this entry.

    Declaration

    Swift

    public func read<ValueType>(at index: Int) throws -> ValueType where ValueType : TupleConvertible

    Parameters

    index

    The index of the entry we want to read.

    Return Value

    The value at that entry.

  • This method reads a range of values as a sub-tuple.

    If the range is outside our bounds, this will throw a ParsingError. If the entry at that index is of a different type, this will throw a ParsingError.

    Throws

    A ParsingError explaining why we can’t read these entries.

    Declaration

    Swift

    public func read(range: CountableRange<Int>) throws -> Tuple

    Parameters

    range

    The range of values we want to read.

    Return Value

    The values at that entry.

  • This method gets a range containing all tuples that have this tuple as a prefix.

    If this tuple contains the entries test and key, this will include the tuple (test, key), and (test, key, foo), but not (test, keys).

    The upper bound of this range will be a special tuple that should not be used for anything other than as the upper bound of a range.

    Declaration

    Swift

    public var childRange: Range<Tuple> { get }
  • This method determines if this tuple has another as a prefix.

    This is true whenever the raw data for this tuple begins with the same bytes as the raw data for the other tuple.

    Declaration

    Swift

    public func hasPrefix(_ prefix: Tuple) -> Bool

    Parameters

    prefix

    The tuple we are checking as a possible prefix.

    Return Value

    Whether this tuple has the other tuple as its prefix.

  • This method gets the hash code for this tuple.

    Declaration

    Swift

    public var hashValue: Int { get }
  • This method increments the last entry in the tuple.

    For an integer entry, this will perform a simple integer increment. If the number exceeds the maximum for the number of bytes we used to store the original number, this will overflow and reset it to zero.

    For a string or data entry, this will increment the byte values for the contents of the entry.

    For all other entries, this will do nothing.

    Declaration

    Swift

    public mutating func incrementLastEntry()
  • This method gets a human-readable description of the tuple’s contents.

    Declaration

    Swift

    public var description: String { get }