Size

public struct Size
extension Size: UnsignedInteger

This is an opaque type for sizes expressed in aggregate bit units, usually 8 bits per unit.

Instances of this type represent a quantity as a multiple of a radix size

  • e.g. the size of a char in bits on the target architecture. As an opaque type, Size protects you from accidentally combining operations on quantities in bit units and size units.

For portability, never assume that a target radix is 8 bits wide. Use Size values wherever you calculate sizes and offsets.

  • Accesses the raw value unitless value of this size.

    Warning

    This accessor breaks the Size abstraction by allowing access to the raw value. The underlying value is unitless and hence any reinterpretation may lead to incorrect results in calculations that depend on precise bit and byte-level arithmetic. This accessor should not be used by user code in general.

    Declaration

    Swift

    public let rawValue: UInt64
  • A size carrying a value of zero.

    Declaration

    Swift

    public static let zero: Size
  • one

    A size carrying a value of one.

    Declaration

    Swift

    public static let one: Size
  • Initializes and returns a size carrying the given value.

    Declaration

    Swift

    public init(_ value: UInt64)
  • Initializes and returns a size carrying the given value which represents a value in bits with a given radix.

    Declaration

    Swift

    public init(bits bitSize: UInt64, radix: UInt64 = 8)

    Parameters

    bitSize

    A given number of bits.

    radix

    The radix value. Defaults to 8 bits per size unit.

  • Returns the value of this size in bits according to a given radix.

    Declaration

    Swift

    public func valueInBits(radix: UInt64 = 8) -> UInt64

    Parameters

    radix

    The radix value. Defaults to 8 bits per size unit.

    Return Value

    A value in bits.

  • Returns true if this size value is a power of two, including if it is zero. Returns false otherwise.

    Declaration

    Swift

    public var isPowerOfTwo: Bool { get }
  • Computes a size with value rounded up to the next highest value that is a multiple of the given alignment value.

    Declaration

    Swift

    public func roundUp(to alignment: Alignment) -> Size

    Parameters

    alignment

    The alignment value. Must not be zero.

    Return Value

    A size representing the given value rounded up to the given alignment value.

  • Returns the remainder of dividing the first size value by the second alignment value. This has the effect of aligning the size value subtractively.

    Declaration

    Swift

    public static func % (lhs: Size, rhs: Alignment) -> Size
  • Declaration

    Swift

    public init<T>(clamping source: T) where T : BinaryInteger
  • Declaration

    Swift

    public init<T>(truncatingIfNeeded source: T) where T : BinaryInteger
  • Declaration

    Swift

    public init?<T>(exactly source: T) where T : BinaryInteger
  • Declaration

    Swift

    public init(integerLiteral value: UInt64)
  • Declaration

    Swift

    public init?<T>(exactly source: T) where T : BinaryFloatingPoint
  • Declaration

    Swift

    public init<T>(_ source: T) where T : BinaryFloatingPoint
  • Declaration

    Swift

    public init<T>(_ source: T) where T : BinaryInteger
  • Declaration

    Swift

    public var words: UInt64.Words { get }
  • Declaration

    Swift

    public var bitWidth: Int { get }
  • Declaration

    Swift

    public var trailingZeroBitCount: Int { get }
  • Declaration

    Swift

    public static func == (lhs: Size, rhs: Size) -> Bool
  • Declaration

    Swift

    public static func < (lhs: Size, rhs: Size) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • Declaration

    Swift

    public static func + (lhs: Size, rhs: Size) -> Size
  • Declaration

    Swift

    public static func += (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func - (lhs: Size, rhs: Size) -> Size
  • Declaration

    Swift

    public static func -= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func * (lhs: Size, rhs: Size) -> Size
  • Declaration

    Swift

    public static func *= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func / (lhs: Size, rhs: Size) -> Size
  • Declaration

    Swift

    public static func /= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func % (lhs: Size, rhs: Size) -> Size
  • Declaration

    Swift

    public static func %= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func &= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func |= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func ^= (lhs: inout Size, rhs: Size)
  • Declaration

    Swift

    public static func >>= <RHS>(lhs: inout Size, rhs: RHS) where RHS : BinaryInteger
  • Declaration

    Swift

    public static func <<= <RHS>(lhs: inout Size, rhs: RHS) where RHS : BinaryInteger
  • Declaration

    Swift

    public prefix static func ~ (x: Size) -> Size
  • Returns true if the given size is a multiple of this size.

    Declaration

    Swift

    public func isMultiple(of other: Size) -> Bool
  • Declaration

    Swift

    public typealias IntegerLiteralType = UInt64
  • Declaration

    Swift

    public typealias Words = UInt64.Words
  • Multiplies a size value by a raw unitless value and produces their product.

    Declaration

    Swift

    public static func * (lhs: Size, rhs: UInt64) -> Size
  • Multiplies a raw unitless value by a size value and produces their product.

    Declaration

    Swift

    public static func * (lhs: UInt64, rhs: Size) -> Size
  • Multiplies a size value by a raw unitless value and stores the result in the left-hand-side size variable.

    Declaration

    Swift

    public static func *= (lhs: inout Size, rhs: UInt64)