swift-collections
swift-collections copied to clipboard
Add `subscript(unsafe:)` to `OrderedSet` to mutate `_elements` via `_modify` when the index is available and the uniqueness invariant upheld
There’s seems to be no way to modify the _elements
memory in place when we want to alter a property that does not partake in the Equatable
and Hashable
conformance. Specifically, I have a struct that’s compared and hashed only on the immutable id
, so unless the struct itself is refactored to include other fields, no safety mishap appears to be possible.
if let index = set.firstIndex(of: element) {
var element = set[index]
element.nonHashedValue = …
set.updateOrAppend(element)
}
if let index = set.firstIndex(of: element) {
set[unsafe: index].nonHashedValue = …
}