diff --git a/Sources/OrderedCollections/OrderedSet/OrderedSet+Insertions.swift b/Sources/OrderedCollections/OrderedSet/OrderedSet+Insertions.swift index 3c9214e2..7b80d118 100644 --- a/Sources/OrderedCollections/OrderedSet/OrderedSet+Insertions.swift +++ b/Sources/OrderedCollections/OrderedSet/OrderedSet+Insertions.swift @@ -210,7 +210,7 @@ extension OrderedSet { /// takes over its position: /// /// var set: OrderedSet = [1, 2, 3] - /// let old = set.replace(4, at: 1) + /// let old = set.replace(at: 1, with: 4) /// // old == 2 /// // set is now [1, 4, 3] /// @@ -218,20 +218,20 @@ extension OrderedSet { /// different index triggers a runtime error, as that would introduce a /// duplicate. /// + /// - Parameter index: The index of the member to replace. It must be a valid + /// index below `endIndex`. + /// /// - Parameter item: The element to place at `index`. It must not already be /// a member of the set, unless it compares equal to the member currently /// at `index`. /// - /// - Parameter index: The index of the member to replace. It must be a valid - /// index below `endIndex`. - /// /// - Returns: The original member that was replaced. /// /// - Complexity: Expected amortized O(1), if `Element` implements /// high-quality hashing. @inlinable @discardableResult - public mutating func replace(_ item: Element, at index: Int) -> Element { + public mutating func replace(at index: Int, with item: Element) -> Element { precondition(index >= 0 && index < count, "Index out of bounds") defer { _checkInvariants() } let (existing, bucket) = _find(item) diff --git a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift index 6c3c4b72..65a548c4 100644 --- a/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift +++ b/Tests/OrderedCollectionsTests/OrderedSet/OrderedSetTests.swift @@ -575,7 +575,7 @@ class OrderedSetTests: CollectionTestCase { var set = OrderedSet(layout: layout, contents: contents) withHiddenCopies(if: isShared, of: &set, checker: { $0._checkInvariants() }) { set in let new = tracker.instance(for: count + offset) // Not yet a member. - let old = set.replace(new, at: offset) + let old = set.replace(at: offset, with: new) expectIdentical(old, contents[offset]) expectIdentical(set[offset], new) expectEqual(set.firstIndex(of: new), offset) @@ -604,7 +604,7 @@ class OrderedSetTests: CollectionTestCase { withHiddenCopies(if: isShared, of: &set, checker: { $0._checkInvariants() }) { set in // Equal to `contents[offset]`, but a distinct instance. let new = tracker.instance(for: offset) - let old = set.replace(new, at: offset) + let old = set.replace(at: offset, with: new) expectIdentical(old, contents[offset]) expectIdentical(set[offset], new) expectEqualElements(set, contents)