mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
[BitSet, OrderedCollections] Unify UnsafeBitSet implementations
This commit is contained in:
29 files changed
+944
-1382
No files matched your search
@@ -158,7 +158,7 @@ extension BitSet: Collection, BidirectionalCollection {
|
||||
/// storage.)
|
||||
public func index(after index: Index) -> Index {
|
||||
_read { handle in
|
||||
assert(handle.isReachable(index._position), "Invalid index")
|
||||
assert(handle._isReachable(index._position), "Invalid index")
|
||||
let pos = handle.index(after: index._position)
|
||||
return Index(_position: pos)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ extension BitSet: Collection, BidirectionalCollection {
|
||||
/// storage.)
|
||||
public func index(before index: Index) -> Index {
|
||||
_read { handle in
|
||||
assert(handle.isReachable(index._position), "Invalid index")
|
||||
assert(handle._isReachable(index._position), "Invalid index")
|
||||
let pos = handle.index(before: index._position)
|
||||
return Index(_position: pos)
|
||||
}
|
||||
@@ -196,8 +196,8 @@ extension BitSet: Collection, BidirectionalCollection {
|
||||
/// addressed by the two input indices.
|
||||
public func distance(from start: Index, to end: Index) -> Int {
|
||||
_read { handle in
|
||||
assert(handle.isReachable(start._position), "Invalid start index")
|
||||
assert(handle.isReachable(end._position), "Invalid end index")
|
||||
assert(handle._isReachable(start._position), "Invalid start index")
|
||||
assert(handle._isReachable(end._position), "Invalid end index")
|
||||
return handle.distance(from: start._position, to: end._position)
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ extension BitSet: Collection, BidirectionalCollection {
|
||||
/// addressed by `index` and the returned result.
|
||||
public func index(_ index: Index, offsetBy distance: Int) -> Index {
|
||||
_read { handle in
|
||||
assert(handle.isReachable(index._position), "Invalid index")
|
||||
assert(handle._isReachable(index._position), "Invalid index")
|
||||
let pos = handle.index(index._position, offsetBy: distance)
|
||||
return Index(_position: pos)
|
||||
}
|
||||
@@ -250,8 +250,8 @@ extension BitSet: Collection, BidirectionalCollection {
|
||||
_ i: Index, offsetBy distance: Int, limitedBy limit: Index
|
||||
) -> Index? {
|
||||
_read { handle in
|
||||
assert(handle.isReachable(i._position), "Invalid index")
|
||||
assert(handle.isReachable(limit._position), "Invalid limit index")
|
||||
assert(handle._isReachable(i._position), "Invalid index")
|
||||
assert(handle._isReachable(limit._position), "Invalid limit index")
|
||||
return handle.index(
|
||||
i._position, offsetBy: distance, limitedBy: limit._position
|
||||
).map { Index(_position: $0) }
|
||||
|
||||
Reference in new issue
Block a user