[BitSet, OrderedCollections] Unify UnsafeBitSet implementations

This commit is contained in:
Karoy Lorentey committed 2022-11-28 16:30:55 -08:00
1 parent c80b844e5e
commit a2f4b18ae0
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) }