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.
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
[ ] I've added at least one test that validates that my change is working, if appropriate
[x] I've followed the code style of the rest of the project
Resolves https://github.com/apple/swift-algorithms/issues/176
When the elements of a sequence are
Hashable
, use aDictionary
to keep track of the counts of elements.The performance depends upon the input, but consistently performs better in large sequences.
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 toXCTAssertEqualSequences
.Checklist