Files
swift-collections/Sources/BitCollections/BitSet/BitSet+Invariants.swift
T
Károly Lőrentey 1d1fbc82d4 [BitSet] Make BitSet generic over its Element
This gets rid of the weird asymmetry between reading the contents of a BitSet (where we used to always get Int values) and mutating it (where we used to be able to give it values fo any fixed-width integer type).
2022-07-30 23:25:53 -07:00

28 lines
919 B
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
extension _BitSet {
#if COLLECTIONS_INTERNAL_CHECKS
@inline(never)
@_effects(releasenone)
public func _checkInvariants() {
let actualCount = _storage.reduce(into: 0) { $0 += $1.count }
precondition(_count == actualCount, "Invalid count")
precondition(_storage.isEmpty || !_storage.last!.isEmpty,
"Extraneous tail slot")
}
#else
@inline(__always) @inlinable
public func _checkInvariants() {}
#endif // COLLECTIONS_INTERNAL_CHECKS
}