BitArray
public struct BitArray
An array of boolean values stored using individual bits, thus providing a very small memory footprint. It has most of the features of a standard array such as constant time random access and amortized constant time insertion at the end of the array.
Conforms to MutableCollection
, ExpressibleByArrayLiteral
, Equatable
, Hashable
, CustomStringConvertible
-
Constructs an empty bit array.
Declaration
Swift
public init()
-
Constructs a bit array from a
Bool
sequence, such as an array.Declaration
Swift
public init<S: Sequence>(_ elements: S) where S.Iterator.Element == Bool
-
Constructs a new bit array from an
Int
array representation. All values different from 0 are consideredtrue
.Declaration
Swift
public init(intRepresentation : [Int])
-
Constructs a new bit array with
count
bits set to the specified value.Declaration
Swift
public init(repeating repeatedValue: Bool, count: Int)
-
Number of bits stored in the bit array.
Declaration
Swift
public fileprivate(set) var count = 0
-
Returns
true
if and only ifcount == 0
.Declaration
Swift
public var isEmpty: Bool
-
The first bit, or nil if the bit array is empty.
Declaration
Swift
public var first: Bool?
-
The last bit, or nil if the bit array is empty.
Declaration
Swift
public var last: Bool?
-
The number of bits set to
true
in the bit array.Declaration
Swift
public fileprivate(set) var cardinality = 0
-
Adds a new
Bool
as the last bit.Declaration
Swift
public mutating func append(_ bit: Bool)
-
Inserts a bit into the array at a given index. Use this method to insert a new bit anywhere within the range of existing bits, or as the last bit. The index must be less than or equal to the number of bits in the bit array. If you attempt to remove a bit at a greater index, you’ll trigger an error.
Declaration
Swift
public mutating func insert(_ bit: Bool, at index: Int)
-
Removes the last bit from the bit array and returns it.
Declaration
Swift
public mutating func removeLast() -> Bool
Return Value
The last bit, or nil if the bit array is empty.
-
Removes the bit at the given index and returns it. The index must be less than the number of bits in the bit array. If you attempt to remove a bit at a greater index, you’ll trigger an error.
Declaration
Swift
public mutating func remove(at index: Int) -> Bool
-
Removes all the bits from the array, and by default clears the underlying storage buffer.
Declaration
Swift
public mutating func removeAll(keepingCapacity keep: Bool = false)
-
Provides random access to individual bits using square bracket noation. The index must be less than the number of items in the bit array. If you attempt to get or set a bit at a greater index, you’ll trigger an error.
Declaration
Swift
public subscript(index: Int) -> Bool
-
Always zero, which is the index of the first bit when non-empty.
Declaration
Swift
public var startIndex : Int
-
Always
count
, which the successor of the last valid subscript argument.Declaration
Swift
public var endIndex : Int
-
Returns the position immediately after the given index.
Returns
The index value immediately afteri
.Declaration
Swift
public func index(after i: Int) -> Int
Parameters
i
A valid index of the collection.
i
must be less thanendIndex
.Return Value
The index value immediately after
i
.
-
Constructs a bit array using a
Bool
array literal.let example: BitArray = [true, false, true]
Declaration
Swift
public init(arrayLiteral elements: Bool...)
-
A string containing a suitable textual representation of the bit array.
Declaration
Swift
public var description: String
-
The hash value.
x == y
impliesx.hashValue == y.hashValue
Declaration
Swift
public var hashValue: Int