Files
swift-collections/Sources/BitCollections/BitSet/BitSet+Invariants.swift
T
Karoy Lorentey 464d973bf3 [BitSet] Remove precalculated count. Add BitSet.Counted wrapper for use cases that require it.
This results in a significant speedup for both individual
insert/remove operations as well as bulk set operations -
up to 4x.

Use cases that require an O(1) count can use the separate
BitSet.Counted type.
2022-08-31 13:04:51 -07:00

28 lines
922 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
}