BitArray

public struct BitArray : Sendable
extension BitArray: Equatable
extension BitArray: Hashable
extension BitArray: MutableCollection
extension BitArray: CustomStringConvertible

An array of bit values represented as Booleans, where true indicates that the bit is on.

  • A position in a BitArray.

    See more

    Declaration

    Swift

    public struct Position : Comparable
  • The value of each bit in the map, represented as a contiguous array of words.

    Declaration

    Swift

    private var bits: [UInt]
  • The number of bits in the array.

    Declaration

    Swift

    public private(set) var count: Int { get }
  • Creates an empty array.

    Declaration

    Swift

    public init()
  • Creates a new array containing count elements with the value b.

    Declaration

    Swift

    public init(repeating b: Bool, count: Int)
  • Creates an array copying the given contents.

    Declaration

    Swift

    public init<S>(_ contents: S) where S : Sequence, S.Element == Bool
  • true iff self is empty.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • true iff all elements in self are false.

    Declaration

    Swift

    public var allFalse: Bool { get }
  • true iff all elements in self are true.

    Declaration

    Swift

    public var allTrue: Bool { get }
  • The number of bits that the array can contain before allocating new storage.

    Declaration

    Swift

    public var capacity: Int { get }
  • Reserves enough space to store n bits in self.

    Declaration

    Swift

    public mutating func reserveCapacity(_ n: Int)
  • Adds a new element at the end of the array.

    Declaration

    Swift

    public mutating func append(_ bit: Bool)
  • Removes and returns the last element in self if it isn’t empty; otherwise returns nil.

    Declaration

    Swift

    public mutating func popLast() -> Bool?
  • Removes and returns the last element in self.

    Requires

    self is not empty.

    Declaration

    Swift

    @discardableResult
    public mutating func removeLast() -> Bool
  • Removes all elements from the array, keeping existing storage if keepingCapacity is true.

    Declaration

    Swift

    public mutating func removeAll(keepingCapacity: Bool = false)
  • Returns the bitwise OR of lhs and rhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func | (lhs: `Self`, rhs: `Self`) -> BitArray
  • Writes the bitwise OR of lhs and rhs to lhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func |= (lhs: inout `Self`, rhs: `Self`)
  • Returns the bitwise AND of lhs and rhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func & (lhs: `Self`, rhs: `Self`) -> BitArray
  • Writes the bitwise AND of lhs and rhs to lhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func &= (lhs: inout `Self`, rhs: `Self`)
  • Returns the bitwise XOR of lhs and rhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func ^ (lhs: `Self`, rhs: `Self`) -> BitArray
  • Writes the bitwise XOR of lhs and rhs to lhs.

    Requires

    self.count == other.count.

    Declaration

    Swift

    public static func ^= (lhs: inout `Self`, rhs: `Self`)
  • Assigns each bits in self to the result of operation applied on those bits and their corresponding bits in other.

    Requires

    self.count == other.count.

    Declaration

    Swift

    private mutating func applyBitwise(_ other: `Self`, _ operation: (UInt, UInt) -> UInt)
  • Sets the value b for the bit at position p.

    Requires

    p is a valid position in self.

    Declaration

    Swift

    private mutating func setValue(_ b: Bool, for p: Position)
  • Declaration

    Swift

    public static func == (l: `Self`, r: `Self`) -> Bool
  • Declaration

    Swift

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

    Swift

    public typealias Index = Position
  • Declaration

    Swift

    public typealias Element = Bool
  • Declaration

    Swift

    public var startIndex: Position { get }
  • Declaration

    Swift

    public var endIndex: Position { get }
  • Declaration

    Swift

    public func index(after p: Position) -> Position
  • Declaration

    Swift

    public subscript(p: Position) -> Bool { get set }
  • Returns startIndex advanced by the given offset.

    Declaration

    Swift

    public func index(at offset: Int) -> Position
  • Returns the offset of position from the start of self.

    Declaration

    Swift

    public func offset(of p: Position) -> Int
  • Accesses the element at given offset.

    Declaration

    Swift

    public subscript(offset: Int) -> Bool { get set }
  • Declaration

    Swift

    public var description: String { get }