Skip to content

Commit e2e2d00

Browse files
committed
[BitSet] Amend return value of update(with:) method
1 parent fb59949 commit e2e2d00

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Sources/BitCollections/BitSet/BitSet+SetAlgebra basics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension BitSet {
104104
/// O(max(`newMember`, *max*)).
105105
@discardableResult
106106
public mutating func update(with newMember: Int) -> Int? {
107-
insert(newMember).inserted ? newMember : nil
107+
insert(newMember).inserted ? nil : newMember
108108
}
109109
}
110110

Tests/BitCollectionsTests/BitSetTests.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Collections open source project
44
//
5-
// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -242,16 +242,12 @@ final class BitSetTest: CollectionTestCase {
242242
var expected: Set<Int> = []
243243
let input = (0 ..< count).shuffled(using: &rng)
244244
withEvery("i", in: input.indices) { i in
245-
let (i1, m1) = actual.insert(input[i])
246-
expected.insert(input[i])
247-
expectTrue(i1)
248-
expectEqual(m1, input[i])
245+
let v = input[i]
246+
expectTrue(actual.insert(v) == expected.insert(v))
249247
if i % 25 == 0 {
250248
expectEqual(Array(actual), expected.sorted())
251249
}
252-
let (i2, m2) = actual.insert(input[i])
253-
expectFalse(i2)
254-
expectEqual(m2, m1)
250+
expectTrue(actual.insert(v) == expected.insert(v))
255251
}
256252
expectEqual(Array(actual), expected.sorted())
257253
}
@@ -265,13 +261,12 @@ final class BitSetTest: CollectionTestCase {
265261
var expected: Set<Int> = []
266262
let input = (0 ..< count).shuffled(using: &rng)
267263
withEvery("i", in: input.indices) { i in
268-
let old = actual.update(with: input[i])
269-
expected.update(with: input[i])
270-
expectEqual(old, input[i])
264+
let v = input[i]
265+
expectEqual(actual.update(with: v), expected.update(with: v))
271266
if i % 25 == 0 {
272267
expectEqual(Array(actual), expected.sorted())
273268
}
274-
expectNil(actual.update(with: input[i]))
269+
expectEqual(actual.update(with: v), expected.update(with: v))
275270
}
276271
expectEqual(Array(actual), expected.sorted())
277272
}
@@ -289,13 +284,11 @@ final class BitSetTest: CollectionTestCase {
289284

290285
withEvery("i", in: input.indices) { i in
291286
let v = input[i]
292-
let old = actual.remove(v)
293-
expected.remove(v)
294-
expectEqual(old, v)
287+
expectEqual(actual.remove(v), expected.remove(v))
295288
if i % 25 == 0 {
296289
expectEqual(Array(actual), expected.sorted())
297290
}
298-
expectNil(actual.remove(v))
291+
expectEqual(actual.remove(v), expected.remove(v))
299292
}
300293
expectEqual(Array(actual), expected.sorted())
301294
}

0 commit comments

Comments
 (0)