Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OrderedDictionary] forward ordered dictionary values equality to values property #335

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Benchmarks/Benchmarks/OrderedDictionaryBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,61 @@ extension Benchmark {
blackHole(d)
}
}

self.add(
title: "OrderedDictionary<Int, Int> equality different instance",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
let right = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
return { timer in
timer.measure {
precondition(left == right)
}
}
}

self.add(
title: "OrderedDictionary<Int, Int> equality same instance",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
let right = left
return { timer in
timer.measure {
precondition(left == right)
}
}
}

self.add(
title: "OrderedDictionary<Int, Int>.Values equality different instance",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
let right = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
return { timer in
timer.measure {
precondition(left.values == right.values)
}
}
}

self.add(
title: "OrderedDictionary<Int, Int>.Values equality same instance",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
let left = OrderedDictionary(uniqueKeysWithValues: keysAndValues)
let right = left
return { timer in
timer.measure {
precondition(left.values == right.values)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ extension OrderedDictionary.Values: MutableCollection {
extension OrderedDictionary.Values: Equatable where Value: Equatable {
@inlinable
public static func ==(left: Self, right: Self) -> Bool {
left.elementsEqual(right)
left._base._values == right._base._values
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,41 @@ import XCTest
import _CollectionsTestSupport

class OrderedDictionaryValueTests: CollectionTestCase {
func test_values_getter() {
func test_values_getter_equal() {
let left: OrderedDictionary = [
"one": 1,
"two": 2,
"three": 3,
"four": 4,
]
let right: OrderedDictionary = [
"one": 1,
"two": 2,
"three": 3,
"four": 4,
]
expectEqual(left.values, left.values) // Identity fast path
expectEqual(left.values, right.values) // Linear algorithm
}

func test_values_getter_not_equal() {
let left: OrderedDictionary = [
"one": 1,
"two": 2,
"three": 3,
"four": 4,
]
let right: OrderedDictionary = [
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
]
expectNotEqual(left.values, right.values)
}

func test_values_getter_equal_elements() {
let d: OrderedDictionary = [
"one": 1,
"two": 2,
Expand Down