Update MutableContainer

- Add `nextMutableSpan(after:)` and `nextMutableSpan(after:maxCount:limitedBy)`, replacing `nextMutableSpan(after:maxCount:)` as the core access primitives
- Add `previousMutableSpan` default algorithms on bidirectional mutable containers
This commit is contained in:
Karoy Lorentey committed 2026-07-20 15:44:35 -07:00
1 parent ef0fba7f7f
commit e75f053e46
12 files changed
+350 -192

No files matched your search

@@ -176,19 +176,30 @@ extension RigidDeque where Element: ~Copyable {
@_lifetime(&self)
public mutating func nextMutableSpan(
after index: inout Int, maxCount: Int
after index: inout Int
) -> MutableSpan<Element> {
_checkValidIndex(index)
precondition(maxCount > 0, "maxCount must be positive")
let segment = self._handle
.nextSegment(after: index)
._extracting(first: maxCount)
let segment = self._handle.nextSegment(after: index)
index &+= segment.count
return _overrideLifetime(
MutableSpan(_unsafeElements: .init(mutating: segment)),
mutating: &self)
}
@_lifetime(&self)
public mutating func nextMutableSpan(
after index: inout Int, maxCount: Int, limitedBy limit: Int
) -> MutableSpan<Element> {
_checkValidIndex(index)
_checkValidIndex(limit)
precondition(maxCount > 0, "maxCount must be positive")
let segment = self._handle.nextSegment(
after: &index, maxCount: maxCount, limitedBy: limit)
return _overrideLifetime(
MutableSpan(_unsafeElements: .init(mutating: segment)),
mutating: &self)
}
@_alwaysEmitIntoClient
public func spanBoundary(before index: Index) -> (index: Index, distance: Int) {
precondition(index >= 0 && index <= count, "Index out of bounds")
@@ -115,9 +115,17 @@ extension UniqueDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(&self)
public mutating func nextMutableSpan(
after index: inout Int, maxCount: Int
after index: inout Int
) -> MutableSpan<Element> {
_storage.nextMutableSpan(after: &index, maxCount: maxCount)
_storage.nextMutableSpan(after: &index)
}
@_alwaysEmitIntoClient
@_lifetime(&self)
public mutating func nextMutableSpan(
after index: inout Int, maxCount: Int, limitedBy limit: Int
) -> MutableSpan<Element> {
_storage.nextMutableSpan(after: &index, maxCount: maxCount, limitedBy: limit)
}
@_alwaysEmitIntoClient