apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.97k stars 443 forks source link

`XCTAssertUnorderedEqualSequences`: Improve algorithmic complexity when elements are `Hashable` (Resolves #176) #177

Open mdznr opened 2 years ago

mdznr commented 2 years ago

Resolves https://github.com/apple/swift-algorithms/issues/176

When the elements of a sequence are Hashable, use a Dictionary to keep track of the counts of elements.

The performance depends upon the input, but consistently performs better in large sequences.

chart halves chart half chart same

For the unit tests that this is used in, the performance wouldn’t be noticeable since it’s only ever working with small collections. However, we can probably move this to a new function that is useful outside of XCTest, like elementsEqual is to XCTAssertEqualSequences.

Checklist